Hibernate:evict()一个持久对象,同时存储它的变化 [英] Hibernate: evict() a persistent object while storing its changes

查看:116
本文介绍了Hibernate:evict()一个持久对象,同时存储它的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 session.save(object)

获得了一个持久化hibernate对象, 。

我想执行 session.evict(object)来节省内存,因为我完成了对象。



evict() here 指出对对象的更改不会被保留。换句话说 - evict会让我失去对该对象所做的更改。



我可以调用 session.flush()

如何在驱逐前持久化对单个持久对象所做的更改?

解决方案

调用 session.save(object) session.saveOrUpdate(object),那么你可以打电话给它,如果你必须的话。但是,在执行此操作之前,您必须刷新会话。会话被设计为基于工作单元的接口,出于很好的理由 - 事务性语义会是没有这种功能的灾难。如果您需要刷新个别实体而不刷新属于同一会话的其他实体,则需要重新考虑您的工作单元。


I have a persistent hibernate object I obtained using session.save(object)

I changed it since.

I want to execute session.evict(object) to save memory, as I am done with the object.

The documentation to 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.

I could call session.flush() but that would flush all changes.

How can I persist changes made to a single persistent object before eviction?

解决方案

Call 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.

这篇关于Hibernate:evict()一个持久对象,同时存储它的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆