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
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.