-->
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.  [ 5 posts ] 
Author Message
 Post subject: Lazy initialization in a stateless environment
PostPosted: Wed Feb 23, 2005 9:23 pm 
Beginner
Beginner

Joined: Wed Feb 09, 2005 10:52 am
Posts: 21
I am using Hibernate 3 with JBoss 4.0 and have a basic question of how to manage my lazy collections in a stateless environment. I have seen a number of ideas tossed around, some involving servlet filters and others with Spring, but most of those are Hibernate 2-centric and, in my opinion, in want of something better.

I am hoping for a clear explanation of how to manage lazy initialization when my only contact with Hibernate occurs in a Stateless EJB. I know about hibernate.transaction.flush_before_completion and hibernate.transaction.auto_close_session, but how else can Hibernate 3 help me when some of my collections aren't accessed until the data gets to the JSP? Am I out of luck with laziness?

Thanks,

Justin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 9:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ask yourself how you would do it if you were using entity beans or JDBC and then you will know how to do it in Hibernate (conceptually, at least).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 9:54 pm 
Beginner
Beginner

Joined: Wed Feb 09, 2005 10:52 am
Posts: 21
gavin wrote:
Ask yourself how you would do it if you were using entity beans or JDBC and then you will know how to do it in Hibernate (conceptually, at least).


It seems like the best answer is to have the method which prepares the page for user viewing ensure that the data has been initialized before directing to that page. It could check collection initialization status before returning the page and only call the session bean if the collection needs to be initialized.

If there is a good probability that all data which pertains to a certain user will be visible at some time during the user's session, shouldn't I just load everything at once when they log in and not try to do it lazily? Through all my reading it has been pounded into my head that only under rare circumstances should anyone use non-lazily initialized collections so I am hesistant to do so.

Any help would be much appreciated.

Thanks,

Justin


Top
 Profile  
 
 Post subject: Re: Lazy initialization in a stateless environment
PostPosted: Thu Feb 24, 2005 9:24 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
JustinAshworth wrote:
I have seen a number of ideas tossed around, some involving servlet filters and others with Spring, but most of those are Hibernate 2-centric and, in my opinion, in want of something better

These are production-tested methods, and I highly recommend them. See the Wiki for a deeper discussion of why Open-Session-In-View is a good pattern.

Spring support for H3 is in CVS now, and will be released around the time of H3. Take a look.

Good luck!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 9:50 pm 
Beginner
Beginner

Joined: Wed Feb 09, 2005 10:52 am
Posts: 21
Thanks for the reply. Since Spring is going to be officially supported in H3 I guess it's time to bite the bullet and learn how to use it.

Thanks,

Justin


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