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
|