Results 1 to 2 of 2

Thread: HibernateTemplate suggestion?

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    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.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

Similar Threads

  1. HibernateTemplate and transactions
    By Simon Brunning in forum Data
    Replies: 4
    Last Post: Mar 9th, 2009, 12:37 AM
  2. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  3. Inject HibernateTemplate into DAO
    By foamdino in forum Data
    Replies: 5
    Last Post: Jul 6th, 2005, 06:56 AM
  4. Replies: 0
    Last Post: May 18th, 2005, 10:04 AM
  5. Replies: 1
    Last Post: Dec 3rd, 2004, 01:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •