在WAS + Spring + Hibernate上事务回滚后吞下异常

时间:2016-07-01 12:17:35

标签: spring hibernate websphere logback

场景:Spring 4.1.5.RELEASE; Hibernate 4.2.1.Final; WAS 8.5.5.5

当数据库操作导致违规异常时(例如:列的值太长),在提交期间抛出UnsupportedOperationException:

WTRN0074E: Exception caught from before_completion synchronization operation: java.lang.UnsupportedOperationException
at org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter.setRollbackOnly(WebSphereExtendedJtaPlatform.java:139)
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.markRollbackOnly(CMTTransaction.java:131)
at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.setRollbackOnly(TransactionCoordinatorImpl.java:306)
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.setRollbackOnly(SynchronizationCallbackCoordinatorImpl.java:126)
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:116)
at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53)
at org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter$TransactionAdapter$1.invoke(WebSphereExtendedJtaPlatform.java:176)
at com.sun.proxy.$Proxy872.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:66)
at com.ibm.tx.jta.impl.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:291)
at com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:153)
at com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2384)
at com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:588)
at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1029)
at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:963)
at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:439)
at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:191)
at com.ibm.ws.uow.UOWManagerImpl.uowCommit(UOWManagerImpl.java:807)
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.uowEnd(EmbeddableUOWManagerImpl.java:881)
at com.ibm.ws.uow.UOWManagerImpl.uowEnd(UOWManagerImpl.java:782)
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderNewUOW(EmbeddableUOWManagerImpl.java:818)
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderUOW(EmbeddableUOWManagerImpl.java:370)
at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:290)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:298)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy783.onMessage(Unknown Source)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:685)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:623)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:591)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:308)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:246)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1142)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1134)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1031)
at java.lang.Thread.run(Thread.java:790)

我发现报告的问题与上述情况类似,但没有人回复或提出解决方案https://hibernate.atlassian.net/browse/HHH-10388

我想要的是记录原因异常,指出问题所在,在这种情况下是违规异常。

我试图将Spring和Hibernate的日志级别从ERROR更改为DEBUG,但仍然没有记录有用的信息。我通过更改应用程序和WAS中的日志设置来完成此操作。

任何想法都会受到赞赏,谢谢。

1 个答案:

答案 0 :(得分:1)

问题不在于吞下的异常,因为即使你有权访问它,你仍然会得到JTA层错误。

来自Hibernate WebSphereExtendedJtaPlatform类javadoc:

  

旨在与WebSphere一起使用的JTA平台实现   应用程序服务器(WAS)。 WAS,与其他所有app服务器不同   planet,不允许直接访问JTS TransactionManager。   相反,对于常见的与事务相关的任务,用户必须使用a   专有API,称为ExtendedJTATransaction。更   不幸的是,在WAS中使用的确切TransactionManagerLookup   高度依赖

     
      
  • WAS版
  •   
  • 将使用Hibernate的WAS容器
  •   
     

据报道,该类适用于任何标准的WAS版本6   J2EE / JEE组件容器。

您正在使用WAS 8,因此UnsupportedOperationException可能是正确的。