Spring @Transactional - Can I Override rollbackFor

Posted by user475039 on Stack Overflow See other posts from Stack Overflow or by user475039
Published on 2011-01-17T19:44:37Z Indexed on 2011/01/17 19:53 UTC
Read the original article Hit count: 126

Filed under:
|
|
|

Hi all,

I am calling a service which has the following annotation:

@Transactional(rollbackFor=ExceptionA.class)
public void myMethodA(....) throws ExceptionA {
.
.
}

I am calling this method from an other method in another Spring Bean.

@Transactional(rollbackFor=ExceptionB.class)
public void mainEntryPointMethod(....) throws ExceptionB {
.
  try {
    myMethodA()
  }
  catch (ExceptionA exp) {
   .
  }


.
}

My problem is that if myMethodA throws an exception, my transaction (which is passed from mainEntryPointMethod -> myMethodA by default propagation) will be marked for rollback. Is there a way in which the 'rollbackFor' for the inner method can be overriden?

Thanks in advance Chris

© Stack Overflow or respective owner

Related posts about java

Related posts about spring