-->
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.  [ 4 posts ] 
Author Message
 Post subject: Demarcation of transactions... use of ThreadLocal
PostPosted: Thu Jun 18, 2009 8:34 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
Hi ... Myself and colleague are introducing Hibernate to our new projects. We have been doing a lot of reading and i personally have tried a number of hibernate tutorials now for over 6 months and he is only the hibernate ship now. We kinda stumbling over the issue of whether to use Dedicated transaction manager or just a straight use of session.beginTransaction(). Our application is a simple CRUD web based and will use struts 1.3 and HIbernate (no experience of other frameworks such as spring). The other battle is whether to follow the ThreadLocal pattern which i support fully, but he doesn't because he believes tomcat cannot work in such environment. He seem to think is not recommended from hibernate.org anymore (ver 3.2-3.3) as it is complex and old perhaps ... Is it not recommended to use ThreadLocal pattern anymore?

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Demarcation of transactions... use of ThreadLocal
PostPosted: Thu Jun 18, 2009 7:10 pm 
Newbie

Joined: Sat Jun 06, 2009 10:17 am
Posts: 4
My sugestion if instead you use the threadlocal object... which leads the code to be hard to read... you store your shared objects on ConcurrentHashMap for example(depending the number of users of your app you even notice any performance issue)... check this class implementation...
ThreadLocal pattern. is recommended to use with 'context' - 'configuration' like objects... (check jbpm implementation of configuration and context object.). Also if you configure your session (current_session_context_class) to thread hibernate will use the threadlocal to store it... is that assumption correct ?

regards.


Top
 Profile  
 
 Post subject: Re: Demarcation of transactions... use of ThreadLocal
PostPosted: Fri Jun 19, 2009 5:51 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
jccanova wrote:
My sugestion if instead you use the threadlocal object... which leads the code to be hard to read... you store your shared objects on ConcurrentHashMap for example(depending the number of users of your app you even notice any performance issue)... check this class implementation...
ThreadLocal pattern. is recommended to use with 'context' - 'configuration' like objects... (check jbpm implementation of configuration and context object.). Also if you configure your session (current_session_context_class) to thread hibernate will use the threadlocal to store it... is that assumption correct ?

regards.


Not sure what you mean by 'contex' but if i set this parameter
Code:
<property name="current_session_context_class">thread</property>


from hibernate.cfg.xml file, does that mean i should now use the ServletFilter to get the currentSession on threadLocal?


Top
 Profile  
 
 Post subject: Re: Demarcation of transactions... use of ThreadLocal
PostPosted: Sun Jun 21, 2009 7:43 pm 
Newbie

Joined: Sat Jun 06, 2009 10:17 am
Posts: 4
No, this means that hibernate session will be stored on a thread local object.

org.hibernate.context.ThreadLocalSessionContext.

which leads with some tricks to take care of unbind the current session at end of the request. if you work with autocommit sessions.. .. you dont have worry about.
but autocommit :P is fun when you talk about hibernate.


Regards.


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