-->
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: Spring - hibernate 4 SessionFactoryUtils
PostPosted: Thu Jun 27, 2013 7:03 am 
Newbie

Joined: Mon Jun 17, 2013 11:56 am
Posts: 4
Considering moving into spring 3.2 with hibernate 4, how should one obtain current session in the context of a transaction? As far as I understand HibernateTransactionManager code (and indeed other TMs) upon beginning a transaction it calls sessionFactory....openSession(), which does NOT set currentSession on hibernate side to this session, but merely returns a new one. Then, the HibernateTransactionManager will maintain the session object using TransactionSynchronizationManager ThreadLocal constructs. Now, if I wanted to access the Session bound to current transaction, I would simply call SessionFactoryUtils.getSession() and that would internally check the TransactionSynchronizationManager for existing session.

Now, in hibernate 4, we do not have that methodology, and we are supposed to use SessionFactory.getCurrentSession() as per HibernateTemplate JavaDoc:

NOTE: As of Hibernate 3.0.1, transactional Hibernate access code can also be coded in plain Hibernate style. Hence, for newly started projects, consider adopting the standard Hibernate3 style of coding data access objects instead, based on SessionFactory.getCurrentSession().

Well, if I am still using HibernateTransactionManager, which uses its OWN session context, and then call SessionFactory.getCurrentSession(), I will not get the current transaction's Session, as I am now referring to hibernate's internal per-thread context, correct? Any pointers would be greatly appreciated


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.