当我运行以下代码时,我得到UnexpectedRollbackException而不是ArrayIndexOutOfBoundsException
环境:Weblogic,Spring,Hibernate,JTA和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]
答案 0 :(得分:0)
我想这是因为Hibernate在您的异常中添加了包装器。
因为您试图在事务中抛出RunTimeException
,所以hibernate将此转换为它自己的UnexpectedRollbackException
例外。
请参阅: - Exception doc
答案 1 :(得分:0)
当您没有在数据库中声明空字段并且在尝试使用JPA保存的实体中,同样的字段为空时也会发生这种情况,因此它会自动回滚事务。