I am using OpenEntityManagerInViewFilter for single web requests where when I query the database, I can pull data from a domain object plus any collections in that domain object per request (hence avoiding lazy loading exceptions)
Here is the issue:
E.g. I have a User object I query for in my web request. It has some collections, like a list of Attributes. I can access Attributes during the same web request which is fine (which is what OpenEntityManagerInViewFilter is useful for)
What I do is save the User object in HTTPSession.
Later on, in some other web page in some other request, I access the User object. When I access any collections of User, I get the infamous LazyInitializationException.
This is a very specific question. How do I access any collections of User at a later time outside of the initial hibernation session (openEntityManagerInView session)??
I have read tons of articles but still haven't bin successful in finding the answer.
Some say use
3) somehow re-attach old session to new session?
4) use new session for existing User object
None of these work and keep in mind I am not working directly with Hibernate Session but with JPA entityManager.
Again, I want to access my domain object's collections in HTTPSession outside of the initial request when I first saved it. There has to be a clean solution to this.
I hope there is a simple answer to this because its pretty frustrating.