java - Spring transaction management. NoRollbackFor not working -
i've got 1 springboot enabled app following setup:
@configuration class annotated @enabletransactionmanagement
transactionmanager defined somewhere in @configuration class:
@bean public platformtransactionmanager transactionmanager() { return new jpatransactionmanager(); } @controller class:
@requestmapping(method = requestmethod.delete, value = "/{entityid}") @transactional(norollbackfor = dataintegrityviolationexception.class) public responseentity<deleteentityresponse> deleteentity(@pathvariable @notnull long entityid) { t existing = getrepository().findone(entityid); try { repository.delete(existing); repository.flush(); deleteentityresponse.setdeleted(true); } catch (final dataintegrityviolationexception ex) { entitymanager.detach(existing); deleteentityresponse.seterrormessage("general.error.delete.dataintegrityviolationexception"); } return new responseentity<>(deleteentityresponse, deleteentityresponse.isdeleted() ? httpstatus.ok : httpstatus.method_not_allowed); } later in same controller class i've defined exception handling method:
@exceptionhandler public responseentity<errorresponse> handleallsortsofexceptions(exception exception) { } i'm expecting when try delete entity , operation fails dataintegrityviolationexception responseentity<deleteentityresponse>, instead i'm getting responseentity<errorresponse>.
responseentity<errorresponse> returned through handleallsortsofexceptions() method. , being called org.springframework.transaction.transactionsystemexception: not commit jpa transaction; nested exception javax.persistence.rollbackexception: transaction marked rollbackonly.
my question - how configure transaction management understands @transactional annotations?
Comments
Post a Comment