Given the transition to spring 3.2 with hibernation 4, how do I get the current session in the context of a transaction? As far as I understand the HibernateTransactionManager code (and, indeed, other TMs), when the transaction sessionFactory....openSession() it calls sessionFactory....openSession() , which does NOT set the current sleep mode session to this session, but simply returns a new one. Then, the HibernateTransactionManager will support the session object using the TransactionSynchronizationManager ThreadLocal constructs. Now, if I wanted to access the Session binding on the current transaction, I would just call SessionFactoryUtils.getSession() and this will internally check the TransactionSynchronizationManager for the existing session.
Now, in hibernate 4, we do not have this methodology, and we must use SessionFactory.getCurrentSession() according to the HibernateTemplate JavaDoc:
NOTE. Starting with Hibernate 3.0.1, the Hibernate transactional access code can also be encoded in the normal sleep mode style. Therefore, for recently launched projects, consider encoding data access objects based on SessionFactory.getCurrentSession () instead of the standard Hibernate3 style.
Well, if I still use the HibernateTransactionManager , which uses its OWN session context and then calls SessionFactory.getCurrentSession() , I wonβt get the current transaction session, since now I mean the hibernate internal sleeping context, right? Any pointers would be greatly appreciated
EDIT: Basically, I'm trying to write my own incarnation of CurrentSessionContext. Previously, I just used SessionFactoryUtils.getSession (sf, true) and returned the current connected session to the stream.
source share