JPA(Hibernate),JTA(JOTM)和Tomcat

时间:2013-09-25 18:07:56

标签: hibernate jpa jta jotm

我正在使用JPA(Hibernate)开发一个应用程序作为后端。 我为每个实体都有一个DAO和JPADAO,我的进程将多个实体更新为一个工作单元,所以我决定使用JTA,因为它允许我控制事务,所以这就是我的代码看起来如何                    的persistence.xml

    <persistence-unit name="Pub" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:comp/env/jdbc/dcapps</jta-data-source>

     <property name="hibernate.dialect" value="org.hibernate.dialect.InformixDialect"/>
        <property name="transactionSynchronizationRegistryName" value="java:comp/env/TransactionSynchronizationRegistry"/>
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JOTMJtaPlatform"/>


            web.xml
      <resource-ref>
  <description>DB Connection</description>
  <res-ref-name>jdbc/dcapps</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>

<resource-env-ref>
<description>JTA transaction manager</description>
<resource-env-ref-name>jta/UserTransaction</resource-env-ref-name>
<resource-env-ref-type>javax.transaction.UserTransaction</resource-env-ref-type>
</resource-env-ref>

    <resource-env-ref>
<description>JTA Transaction Synchronization Registry</description>
<resource-env-ref-name>TransactionSynchronizationRegistry</resource-env-ref-name>
<resource-env-ref-type>javax.transaction.TransactionSynchronizationRegistry
 </resource-env-ref-type>
 </resource-env-ref>


         content.xml(Tomcat 7)
        <Resource name="jdbc/dcapps" auth="Container" type="javax.sql.DataSource"
               maxActive="20" maxIdle="10" maxWait="-1"
               username="dcapps" password="dcapps" driverClassName="com.informix.jdbc.IfxDriver"
               url="jdbc:informix-sqli://fddb.fd.gtwy.dcn:7101/fd_test:INFORMIXSERVER=fd_ecf"/>

 <Resource
        name="TransactionSynchronizationRegistry"
        auth="Container"
        type="javax.transaction.TransactionSynchronizationRegistry"
        factory="org.objectweb.jotm.TransactionSynchronizationRegistryFactory"/>

<Transaction
        factory="org.objectweb.jotm.UserTransactionFactory"
        jotm.timeout="60"/>





        Process.java
       Context initContext = new InitialContext();
     utx  = (UserTransaction)initContext.lookup("java:comp/UserTransaction");
             dktPartDAO.getEntityManager().joinTransaction();
            dkttextDAO.getEntityManager().joinTransaction();
            reqHDAO.getEntityManager().joinTransaction();
            reqDDAO.getEntityManager().joinTransaction();
            costDAO.getEntityManager().joinTransaction();
            reportDDAO.getEntityManager().joinTransaction();
            caseflagDAO.getEntityManager().joinTransaction();
            redStatusDAO.getEntityManager().joinTransaction();
            pcdktPartDAO.getEntityManager().joinTransaction();
            pcDkttextDAO.getEntityManager().joinTransaction();
                           utx.commit();

现在,当我尝试开始一个事务并提交对实体(多个)的更改时,它会抛出异常并调用utx.rollback但它不会回滚它只提交了事务而不是所有实体都被保存

         Exception
      java.lang.IllegalStateException: Cannot get Transaction for rollback
at org.objectweb.jotm.Current.rollback(Current.java:486)
at pub.jpa.dto.support.PubDProcess.processRecords(PubDProcess.java:397)

         org.omg.CORBA.BAD_INV_ORDER: The Servant has not been associated with an ORB instance  vmcid: 0x0  minor code: 0  completed: No
at org.omg.PortableServer.Servant._get_delegate(Unknown Source)
at org.omg.PortableServer.Servant._poa(Unknown Source)
at org.objectweb.jotm._SubCoordinator_Tie.deactivate(Unknown Source)
at com.sun.corba.se.impl.javax.rmi.CORBA.Util.cleanUpTie(Unknown Source)
at com.sun.corba.se.impl.javax.rmi.CORBA.Util.unexportObject(Unknown Source)
at javax.rmi.CORBA.Util.unexportObject(Unknown Source)
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.unexportObject(Unknown Source)
at javax.rmi.PortableRemoteObject.unexportObject(Unknown Source)

1 个答案:

答案 0 :(得分:0)

您没有提到您正在使用的JOTM版本,但我在使用v2.2.1时遇到了完全相同的问题。降级到版本v2.1.9为我解决了这个问题。

显然最近已修复,请参阅http://websvn.ow2.org/comp.php?repname=jotm&compare[]=/@1174&compare[]=/@1175

亲切的问候,

百里