-->
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: session.iterate() & session handling
PostPosted: Tue Nov 25, 2003 1:48 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
Hi,

I'd like some advice on handling session.iterate().

So far my hibernate usage pattern for storing/loading object has been: open session->load/save->close session->return to business layer. Now, I'm adding support for loading large lists of records using session iterate and this usage breaks down as I cannot close the session until after I am done iterating through the result set.

Here's my question. Given that I don't what the business logic layer to know anything about the underlying persistence layer (except the fact that it exists), how do I make sure the session gets closed after I'm done using the iterator?


Thanks
Dmitry


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 1:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
AOP and interception points on your business boundaries.
Interceptor implements Thread local Session pattern (see the wiki)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:39 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
I may not have worded my question correctly (or I misunderstood the reply). What I meant to ask was: what's the best way to close the session after the business layer is done using the iterator, assuming that I don't want the business layer to know about the session's existance.


Top
 Profile  
 
 Post subject: Open Session in View
PostPosted: Tue Nov 25, 2003 3:16 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
http://www.hibernate.org/43.html

Can you use this pattern? (you don't need to do exactly what's in the example, if you aren't using servlets you can still use a ThreadLocal in something else that gets called before and after your business layer)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 4:21 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
If you'd use the Spring Framework's transaction management, the Hibernate Session would get closed after transaction commit, through automatic transaction synchronization. This works with both HibernateTransactionManager and JtaTransactionManager.

Your business layer would just know about generic transaction demarcation, or not even about that when using declarative demaration via AOP, but not about any details of the persistence layer.

Juergen


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:46 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
thanks guys!!! David, that link was great. It helped me finally understand what Emmanual meant by his reply.


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.