开发者

How to detach all objects from Hibernate session

开发者 https://www.devze.com 2023-01-16 19:37 出处:网络
From time to time I need to clean Hibernate session. How to prevent LazyInitializationException with obects that are attached to this session?

From time to time I need to clean Hibernate session.

How to prevent LazyInitializationException with obects that are attached to this session?

I am searching for something like session.detachAllObjects(). and then invoke session.clear()

After this I suppose these objects will be retrieved 开发者_运维知识库from DB.


session.clear() detaches all objects.

LazyInitializationException usually means that the entities are detached from a session, or a session is closed. If you want to avoid it, attach an object to a session (using session.merge(..)), or don't close it (using OpenSessionInView)

0

精彩评论

暂无评论...
验证码 换一张
取 消