-->
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: Why store session in a thread local variable?
PostPosted: Thu Jan 22, 2004 4:40 pm 
Newbie

Joined: Thu Jan 22, 2004 3:59 pm
Posts: 1
Hello,

There are FAQs and Best Practices which suggest storing
Quote:
the session in a thread local variable. I was wondering wh
y this is done, and how this works in an environment with distributed transactions.

It seems to me as if it would be easier and cleaner to perform "Each interaction with the persistent store in a new Session" (http://www.hibernate.org/hib_docs/refer ... tions.html), i.e. open & close for each access.

the design I'm looking at is Session Facade -> DAO -> Hibernate

From the examples I've seen, there was very clear transaction demarcation, e.g. from a Session Facade. However, with distributed transactions, the Transaction can be demarcated completely outside the Session Facade (e.g. from a remote app server which is calling into the Session Facade). In this case, there is no way of knowing when the transaction ends, and no way of closing the session.

Thanks,

Vj


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 5:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you do open/close on each access, you loose the session cache, object identity, etc.

I am using the second version (the reference counting one) of the ThreadLocalSession class for EJBs, where you can detect when the session can actually be closed (have to be very careful with exception handling though)


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.