Announcement Announcement Module
Collapse
No announcement yet.
HibernateTemplate suggestion? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateTemplate suggestion?

    Hi

    How about adding these methods to HibernateTemplate?

    public org.hibernate.Transaction getCurrentHibernateTransaction() {

    SessionFactory sessionFactory = (SessionFactory)getBean("sessionFactory");
    SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.g etResource(sessionFactory);
    Transaction currentTransaction = null;

    if (sessionHolder!=null) {
    currentTransaction = sessionHolder.getTransaction();
    }
    return currentTransaction;
    }

    //-----------------------------------------------------------------------//

    public org.hibernate.Session getCurrentHibernateSession() {

    SessionFactory sessionFactory = (SessionFactory)getBean("sessionFactory");
    SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.g etResource(sessionFactory);
    org.hibernate.Session currentSession = null;

    if (sessionHolder!=null) {
    currentSession = sessionHolder.getSession();
    }
    return currentSession;
    }

  • #2
    Out of curiosity, why would you want to get the Hibernate transaction? Normally, using Spring, as when using EJB, you will use Spring's transaction infrastructure rather than the "local" transaction infrastructures of each resource, which can cause problems if you're, say, mixing Hibernate and JDBC.

    Comment

    Working...
    X