-->
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.  [ 6 posts ] 
Author Message
 Post subject: Lazy loading in web application
PostPosted: Mon Jun 26, 2006 5:53 am 
Newbie

Joined: Sun Jun 04, 2006 8:41 pm
Posts: 13
Is it possible to use lazy loading in a web application. In this case I can't close the session and I have to reconnect the session. If different people work with the web application how can the changes be forwarded to other users. My problem is that the data persisted in the mysql database can only be made visible to other users if I use the session.clear or session.close. In this case the lazy objects in the cache are no longer available. In the other case the cache is not checking if there are updated data in the database.

Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 10:10 pm 
Newbie

Joined: Fri Jun 23, 2006 1:46 pm
Posts: 5
We use lazy loading in our web application. As I understand it a session is only supposed to remain open for the duration of a logical unit of work (which may of course span several DB transactions). For us this means we only keep the session open for the duration of a single HTTP request. We use a request filter to open a Session at the beginning of the filter chain, and then close it at the end. Of course this means that any objects with lazy collections that live for longer than the duration of a single http request (for example any object you might store in the http session) can generate a LazyInitializationException if you try to access the lazy loaded collection after the hibernate Session is closed.
We’ve never found a good way around this problem short of being careful what we store in the http session. If all else fails, if you find yourself getting a LazyInitializationException you can re-read the offending object before accessing the collection, although this kind of defeats the point hanging on to it between requests.
I don’t know if this setup would be sufficient for your purposes or not. I guess it all depends on what you’re trying to do. Could you be more specific on what your webapp does?


Top
 Profile  
 
 Post subject: Details
PostPosted: Tue Jun 27, 2006 2:54 am 
Newbie

Joined: Sun Jun 04, 2006 8:41 pm
Posts: 13
Hello mjtaylor24601,
it's really a simple application. I have to realize a shared pool of ressources between company. The database is holding the actual data. A simple listcontrols, in my way realized with the tag library "common controls" visualize the data in a list control. The architecture based on Tomcat and struts.

At present I hold the hibernate session in the httprequest and reconnect the session with each request. This is ok if I work within one browser session. If other users work within other browser session that data is not visible. I understand that hibernate does not share objects of different sessions. But I thought that if data are changed in the database each hibernate session should become notice from that. But that is not the case. So the only way is to clear or close the session.

I wish that it is possible in Hibernate that I can define that Hibernate has to call the database in every case.

Do you have other ideas? I think that I use hibernate in wrong way.


Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 4:04 am 
Newbie

Joined: Fri Jan 13, 2006 1:40 pm
Posts: 11
If you are using Spring Framework, you can keep the Session open in the view layer also.
U can check the following link

http://www.hibernate.org/43.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 9:14 pm 
Newbie

Joined: Fri Jul 07, 2006 1:30 pm
Posts: 6
I got the same problem.

Thanks that link looks like it would solve the problem. But it just seems like a complicated a workaround making everything more fragile. Its cool Hibernate has all these fancy features like lazy loading, caching, but as in this case the lazy loading is done after the session is closed, all these things it does for you automatically just make things more difficult and creates new issues not easily debugged.

The more of these kind of issues I hit, the more I'm leaning toward ibatis or a jdbc-wrapper framework.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 9:22 pm 
Newbie

Joined: Fri Jul 07, 2006 1:30 pm
Posts: 6
How can I tell Hibernate (at the individual transaction level) to force Non-Lazy loading of a List in my Object so that it just loads the Object.subList initially and therefore won't do the load later in my view rendering?

Is it possible to set Non-Lazy loading not just at the mapping level but change it for different transactions on the same object?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.