Commit and Rollback options
We are using annotation driven transaction management in our application.
There are three layers
application layer -> layer1 -> layer2
application layer : PROPAGATION.REQUIRES_NEW
The issue we are facing is in the application layer I have to catch and process a run time exception .
But when we do that we are getting the following exception
ERROR org.codehaus.xfire.handler.DefaultFaultHandler - Fault occurred!
org.springframework.transaction.UnexpectedRollback Exception: Transaction rolled back because it has been marked as rollback-only
at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:626)
at org.springframework.transaction.interceptor.Transa ctionAspectSupport.commitTransactionAfterReturning (TransactionAspectSupport.java:314)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:117)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
so in the exception handling code we used the TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly();
This doesn't give the earlier exception but it roll backs the trx i.e. doesn't commit the changes to the DB
How can we catch the exception and at the same time commit changes to the DB.
It sounds like you should declare a no-rollback rule, this will commit the transaction for work done up to where the exception was thrown. See the reference doc section Rolling Back for some more information.
BTW, This is the Spring .NET forum, the forum for Java related question is at forum.springframework.org