UnexpectedRollbackException - JTA transaction unexpectedly rolled back

北慕城南 提交于 2020-05-16 20:30:49

问题


When I run the below code, I get UnexpectedRollbackException instead of ArrayIndexOutOfBoundsException

Environment: Weblogic, Spring, Hibernate, JTA and EJB

Code:

public class ServiceImpl    
{        
    @Transactional  
    public void test()  
    {                   
        throw new ArrayIndexOutOfBoundsException();                 
    }   
}



public class WebLayerClass  
{           
    service.test(); 
}  

log:

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]

回答1:


I guess this is due to Hibernate has added wrapper on your exception. Because you are trying to throw RunTimeException inside a transaction,hibernate converts this to it's own UnexpectedRollbackException exception.

See:- Exception doc




回答2:


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.



来源:https://stackoverflow.com/questions/32456284/unexpectedrollbackexception-jta-transaction-unexpectedly-rolled-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!