-->
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: purpose of ThreadLocalSessionContext
PostPosted: Thu Oct 25, 2007 4:54 am 
Beginner
Beginner

Joined: Tue Feb 08, 2005 7:01 am
Posts: 21
ThreadLocalSessionContext provides on demand session creation - at least in theory. The returned session doesn't work until the user code explicity starts a transaction. So what is user code supposed to do? Request a session and verify if a transaction already started? This seems to defeat the purpose of on demand session creation.

Another thing is that opening and committing a transaction on non-transactional MySQL tables is pure overhead - 2 unnecessary round-trip to the server. Why is this forced? To not forget to close the session context? If my code forget that to explicitly close the ThreadLocalSessionContext then in the same way it can forget to commit or rollback the transaction.

I thought I write my own CurrentSessionContext implementation. But then I noticed that this interface returns a Hibernate 2 Session. Which is compatible with Hibernate 3 Session but contains many deprecated methods. Why does it return the old compatibility interface when it was written for the 3.1 series?


Hibernate version: 3.2.2

Name and version of the database you are using:
MySQL / myisam


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 11:34 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
It is there to provide a mechanism to get the current session for the life of the current thread. It's useful so you don't have to pass a session reference all around to use the same session. You are still responsible for transaction management.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


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.