Reputation: 223
Is it possible to tell Spring to rollback for exception MyException
as well as RuntimeException
in the XML configuration while using @transactional
?
I know it is possible to set the rollback for in the annotation but it seems redundant if I have lots of services that would all set the same exceptions.
I saw peoples suggesting to create a custom transactional annotation but I'd prefer not to use a custom annotation and stick with a Spring one.
I know that its possible to use advices but never saw examples where you can use the annotation at the same time.
Upvotes: 3
Views: 860
Reputation: 2257
you can simply achieve this by using spring transaction advice tags:
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="*" rollback-for="MyException" no-rollback-for="OtherException"/>
</tx:attributes>
</tx:advice>
check Spring doc transaction management section for more details: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html
Upvotes: 3