How to use Atomikos Transaction Essentials with Hibernate >= 4.3

前端 未结 5 473
悲&欢浪女
悲&欢浪女 2020-12-09 05:54

I switched from Hibernate 4.2 to Hibernate 4.3 and my project is not working any more. I\'m getting an

HibernateException: Unable to locate current JT

5条回答
  •  旧巷少年郎
    2020-12-09 06:25

    In Hibernate 4.3 the long deprecated TransactionManagerLookup got removed. Now the JTA provider must implement org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform. An abstract implementation of JTA Platform is already available within Hibernate namely org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform. Using this it is quite simple to write a JTA Platform for Atomikos:

    package test;
    
    import javax.transaction.TransactionManager;
    import javax.transaction.UserTransaction;
    import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform;
    import com.atomikos.icatch.jta.UserTransactionManager;
    
    public class AtomikosJtaPlatform extends AbstractJtaPlatform {
    
      private static final long serialVersionUID = 1L;
      private UserTransactionManager utm;
    
      public AtomikosJtaPlatform() {
        utm = new UserTransactionManager();
      }
    
      @Override
      protected TransactionManager locateTransactionManager() {
        return utm;
      }
    
      @Override
      protected UserTransaction locateUserTransaction() {
        return utm;
      }
    }
    

    In addition the name of the platform implementation class must be added to the hibernate configuration:

    test.AtomikosJtaPlatform
    

提交回复
热议问题