-->
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.  [ 1 post ] 
Author Message
 Post subject: session per operation vs session per thread with autocommit?
PostPosted: Thu May 28, 2009 12:48 am 
Regular
Regular

Joined: Wed Jan 21, 2009 8:41 pm
Posts: 54
In general is it considered bad form to use a Session without explicit transaction boundaries when using session per thread via getCurrentSession() ?

ie. it's very easy to end up with closed sessions coming back from getCurrentSession
if you use Session without explicit transaction boundaries because underneath the Session gets closed for you?

Is that true?

I have some code that currently wraps hibernate or attempts to and in order to do so uses session per operation. In order to avoid performance issues with select-before-update I need to convert the code to session per thread so that the session is longer lived. Right now the existing code does a lot of fetches without explicit transaction boundaries and I'm thinking that's the cause of the "Already closed" type messages.

I had assumed that I could be in charge of how the Session is used and used my own ThreadLocal to house my Session and it's removed from the ThreadLocal when the session is closed via the wrapper however it appears that somehow elsewhere the Session is closed and left inside the ThreadLocal and if it's expected that Hibernate can close a Session like this then it means that I'm forced to use ThreadLocalSessionContext and not my own ThreadLocal and that means that I'm required to have called beginTransaction on the Session before it can be used thus I'm actually forced into using explicit transaction boundaries whenever I want the Session bound to a Thread.


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

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.