本文介绍了UnexpectedRollbackException-JTA事务意外回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行以下代码时,我得到的是UnexpectedRollbackException而不是ArrayIndexOutOfBoundsException
When I run the below code, I get UnexpectedRollbackException instead of ArrayIndexOutOfBoundsException
环境:Weblogic,Spring,Hibernate,JTA和EJB
Environment: Weblogic, Spring, Hibernate, JTA and EJB
代码:
public class ServiceImpl
{
@Transactional
public void test()
{
throw new ArrayIndexOutOfBoundsException();
}
}
public class WebLayerClass
{
service.test();
}
日志:
Caused by: org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is weblogic.transaction.RollbackException: setRollbackOnly called on transaction
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1024) ~[spring-tx-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757) ~[spring-tx-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726) ~[spring-tx-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478) ~[spring-tx-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272) ~[spring-tx-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at com.sun.proxy.$Proxy261.update(Unknown Source) ~[na:na]
at de.unicreditgroup.esa.service.webtool.sql.WebToolSqlServiceImpl.updateSqlQuery(WebToolSqlServiceImpl.java:234) ~[de-unicreditgroup-esa-services-2.1.0-SNAPSHOT.jar:na]
推荐答案
当您在数据库中没有声明null字段并且尝试使用JPA保存的Entity中,同样的字段为null时也会发生这种情况,因此它会自动回滚交易.
This happen also when you have not null field declared in database and in the Entity you are trying to save using JPA the same field is null so automatically it rolls back the transaction.
这篇关于UnexpectedRollbackException-JTA事务意外回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!