Hibernate:evict()一个持久对象,同时存储它的变化 [英] Hibernate: evict() a persistent object while storing its changes
问题描述
我使用 session.save(object)
获得了一个持久化hibernate对象, 。
我想执行 session.evict(object)
来节省内存,因为我完成了对象。
我可以调用 如何在驱逐前持久化对单个持久对象所做的更改? 调用 I have a persistent hibernate object I obtained using I changed it since. I want to execute The documentation to I could call How can I persist changes made to a single persistent object before eviction? Call 这篇关于Hibernate:evict()一个持久对象,同时存储它的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! session.flush()$ c
session.save(object)
或 session.saveOrUpdate(object)
,那么你可以打电话给它,如果你必须的话。但是,在执行此操作之前,您必须刷新会话。会话被设计为基于工作单元的接口,出于很好的理由 - 事务性语义会是没有这种功能的灾难。如果您需要刷新个别实体而不刷新属于同一会话的其他实体,则需要重新考虑您的工作单元。session.save(object)
session.evict(object)
to save memory, as I am done with the object.evict()
here states that changes to the object will not be persisted. In other words - evict will cause me to lose changes I did to the object.session.flush()
but that would flush all changes.session.save(object)
or session.saveOrUpdate(object)
, then you can call evict on it if you must. However, you must flush the session before doing this. The session is designed to be a unit-of-work based interface, for good reason -- transactional semantics would be a disaster without this feature. If you need to flush individual entities without flushing others that are part of the same session, you need to rethink your unit-of-work.