I’m developing a web application in which the model consists a Group which contains a List of many Users. A HTTP request comes to show the Group. The Users are loaded with FetchType.LAZY because I don’t want them all right away. The Group is saved into the HTTP session and the Hibernate Session is closed. The application then responds by showing the Group name and description. A new HTTP request might then come in to show some users from the group. The Group is pulled from the HTTP Session and the application tries to access the list. Won’t Hibernate throw an Exception since the proxies for each User were tied to the Hibernate Session that was previously closed? How do I do lazy loading across HTTP requests within HTTP sessions?
I’m developing a web application in which the model consists a Group which contains
Share
You should not put users nor groups (as objects) in the session. The best scenario is to put group id in the session and load the group and users if/when necessary.
Worried about the performance? Let the Hibernate 2nd level cache solve this problem. The cache should even support retrieving all users by group if you configure object mappings correctly, something like: