4

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]
Raghu ram
  • 61
  • 1
  • 1
  • 6

2 Answers2

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

dReAmEr
  • 6,986
  • 7
  • 36
  • 63
  • thanks a lot for the reply. I have different business cases to be executed in web layer based on the exception from service. So in this case catch block with 'ArrayIndexOutOfBoundsException' will not catch 'UnexpectedRollbackException'. How perform i unwrap the exception ? Doesn't the framework do unwrapping ? – Raghu ram Sep 09 '15 at 05:59
  • For jta, looks like its an open issue in spring https://jira.spring.io/browse/SPR-9053 – Raghu ram Sep 09 '15 at 06:08
  • Can you please support me to add a work around for unwrap and catch the exception. – Raghu ram Sep 09 '15 at 13:19
  • Got the same issue. any work around to prevent Hibernate from wrapping our custom defined exceptions? – Adarsh D Dec 14 '21 at 12:22
1

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.