问题
I am trying to make a transaction fail for all the unchecked exceptions except for a particular unchecked exception(in my case - DuplicateKeyException). How can I achieve this customization using @Transactional annotation of Spring framework ?
Thank you!
回答1:
Try the noRollbackFor option
@Transactional(noRollbackFor=DuplicateKeyException.class)
回答2:
Do it like this :
public void driverMethod(){
try{
BeforeException()
}
catch(DuplicateKeyException e)
AfterException()
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
private BeforeException(){
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
private AfterException(){
}
来源:https://stackoverflow.com/questions/18754357/transactional-propogate-transactions-only-for-a-few-exceptions