-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Lazy Load between web requests
PostPosted: Wed Nov 18, 2009 6:18 pm 
Beginner
Beginner

Joined: Fri Nov 13, 2009 4:05 pm
Posts: 30
I have an entity called User that has several lazy loaded property relationships with other entities. I am using the OpenEntityManagerInView class in order to bind the hibernate session when each request comes into Struts2/Spring2.

The problem I am encountering is that during the login process, the User entity is queried but not fully populated because the additional relationships are not iterated during the login process. When the user navigates to another page, those properties are iterated from the cached user object that was stored in the session, but the page errors with a LazyInitializationException.

Is it possible to lazily initialize properties in this way between two requests to a Struts2/Spring web application?


Top
 Profile  
 
 Post subject: Re: Lazy Load between web requests
PostPosted: Thu Nov 19, 2009 2:55 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Lazy initialization works only till the hibernate session is open. Once you close the hibernate session, lazy initialization cannot happen and ends up throwing LazyInitializationException. There are two solutions to this problem:
1) Keep the session open till you are sure you will not do any more lazy loading. This approach may not be useful for multi-tiered web applications as most applications will close the session in the model.
2) Use Hibernate.initialize(entity) to load you entity/relationships before closing your session. This is the usual approach that multi-tiered application use. In my application I use this approach. For details on inititalization please visit:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-fetching-initialization

Hope that helps.

_________________
Sukirtha


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.