2014-03-31 100 views
1

編輯 - 我有這麼看來有什麼毛病休眠4選中此組合:XAER_OUTSIDE異常 - 春季4.0.3 - 休眠4.1.12 - JTA - 8的Websphere - DB2

  • 彈簧4 + JPA +休眠4 - >異常
  • 彈簧4 +休眠4 - >異常
  • 彈簧4 + JPA +休眠3 - >行
  • 彈簧4 +休眠3 - >行
  • 彈簧3 + JPA - 休眠4 - >異常
  • 彈簧3 + JPA - 休眠3 - >行
  • 彈簧3 + Hibernate 3的 - >行

我最近升級距離Spring 3.2應用/休眠3.6.10到Spring 4.0.3 + Hibernate 4.1.12。我的環境是IBM Websphere 8.0.0.7和DB2,並且該應用程序被配置爲使用XA數據源。

的一點是,在第一數據庫調用(後續調用總是OK)我得到這個錯誤:

@Transactional(readOnly = true) 
public Foo loadFoo(int id) { 
    LOG.debug("load {}", id); 
    FooEntity fe = fooDAO.findOne(id); 
    ... 
} 

org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'fooRestController' 
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'globalControllerAdvice' 
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'org.springframework.transaction.interceptor.TransactionInterceptor#0' 
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'transactionManager' 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; '' 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Invoking WebSphere UOW action: type=1, join=false 
org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource DEBUG - Adding transactional method 'findOne' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; '' 
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'transactionManager' 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; '' 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Invoking WebSphere UOW action: type=1, join=true 
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Opening JPA EntityManager 
org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl DEBUG - Skipping JTA sync registration due to auto join checking 
org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl DEBUG - successfully registered Synchronization 
org.hibernate.ejb.AbstractEntityManagerImpl DEBUG - Looking for a JTA transaction to join 
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Registering transaction synchronization for JPA EntityManager 
org.hibernate.loader.Loader DEBUG - Loading entity: [com.mycompany.spring4.entity.FooEntity#17027] 
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Obtaining JDBC connection 
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Obtained JDBC connection 
DSRA0304E: XAException occurred. XAException contents and details are: "". 
DSRA0302E: XAException occurred. Error code is: XAER_OUTSIDE (-9). Exception is: XAER_OUTSIDE 
J2CA0027E: An exception occurred while invoking start on an XA Resource Adapter from DataSource jdbc/LOCDBD1_XA, within transaction ID {XidImpl: formatId(57415344), gtrid_length(36), bqual_length(54), 
data(0000014517a4c063000000015e7f81b4c90865e6b88e167905e5d2ed67f44ed6409cba5c0000014517a4c063000000015e7f81b4c90865e6b88e167905e5d2ed67f44ed6409cba5c000000010000000000000000000000000001)} : com.ibm.db2.jcc.c.zh: XAER_OUTSIDE 

Caused by: javax.transaction.RollbackException: XAResource working outside transaction 
    at com.ibm.tx.jta.impl.RegisteredResources.startRes(RegisteredResources.java:1019) 
    at com.ibm.ws.tx.jta.RegisteredResources.enlistResource(RegisteredResources.java:1113) 
    at com.ibm.ws.tx.jta.TransactionImpl.enlistResource(TransactionImpl.java:2214) 
    at com.ibm.tx.jta.impl.EmbeddableTranManagerSet.enlist(EmbeddableTranManagerSet.java:150) 
    at com.ibm.ejs.j2c.XATransactionWrapper.enlist(XATransactionWrapper.java:727) 
    ... 140 more 
Caused by: com.ibm.db2.jcc.c.zh: XAER_OUTSIDE 
    at com.ibm.db2.jcc.b.bc.a(bc.java:1651) 
    at com.ibm.db2.jcc.b.bc.start(bc.java:1530) 
    at com.ibm.ws.rsadapter.spi.WSRdbXaResourceImpl.start(WSRdbXaResourceImpl.java:1525) 
    at com.ibm.ejs.j2c.XATransactionWrapper.start(XATransactionWrapper.java:1475) 
    at com.ibm.ws.Transaction.JTA.JTAResourceBase.start(JTAResourceBase.java:153) 
    at com.ibm.tx.jta.impl.RegisteredResources.startRes(RegisteredResources.java:1002) 
    ... 144 more 

這是第二次和成功的呼叫記錄追蹤:

org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'fooRestController' 
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'globalControllerAdvice' 
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'transactionManager' 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; '' 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Invoking WebSphere UOW action: type=1, join=false 
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'transactionManager' 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; '' 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Invoking WebSphere UOW action: type=1, join=true 
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Opening JPA EntityManager 
org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl DEBUG - Skipping JTA sync registration due to auto join checking 
org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl DEBUG - successfully registered Synchronization 
org.hibernate.ejb.AbstractEntityManagerImpl DEBUG - Looking for a JTA transaction to join 
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Registering transaction synchronization for JPA EntityManager 
org.hibernate.loader.Loader DEBUG - Loading entity: [com.mycompany.spring4.entity.FooEntity#17027] 
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Obtaining JDBC connection 
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Obtained JDBC connection 
org.hibernate.loader.Loader DEBUG - Result set row: 0 
org.hibernate.loader.Loader DEBUG - Result row: EntityKey[com.mycompany.spring4.entity.FooEntity#17027] 
org.hibernate.engine.internal.TwoPhaseLoad DEBUG - Resolving associations for [com.mycompany.spring4.entity.FooEntity#17027] 
org.hibernate.engine.internal.TwoPhaseLoad DEBUG - Done materializing entity [com.mycompany.spring4.entity.FooEntity#17027] 
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Releasing JDBC connection 
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Released JDBC connection 
org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler DEBUG - HHH000163: Logical connection releasing its physical connection 
org.hibernate.loader.Loader DEBUG - Done entity load 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Returned from WebSphere UOW action: type=1, join=true 
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Closing JPA EntityManager 
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Aggressively releasing JDBC connection 
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Returned from WebSphere UOW action: type=1, join=false 

我CFG的相關部分是:

<bean id="mainEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="persistenceUnitName" value="mainPersistenceUnit"/> 
    <property name="jtaDataSource" ref="mainDataSource"/> 
    <property name="packagesToScan" ref="packages-mainEntityManagerFactory"/> 
    <property name="jpaProperties"> 
     <props> 
      <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform</prop> 
      <prop key="hibernate.current_session_context_class">jta</prop> 
      <prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory</prop> 
     </props> 
    </property> 
    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/> 
    </property> 
    <property name="jpaDialect"> 
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/> 
    </property> 
</bean> 

<tx:annotation-driven order="0" /> 

<bean name="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"> 
    <property name="allowCustomIsolationLevels" value="true" /> 
</bean> 

任何想法爲什麼它第一次被稱爲失敗?

回答

1

自己升級到Spring 4.1.6和Hibernate 4.2.19解決了這個問題。我想這是一個與Hibernate相關的問題。