Spring transaction failure scenarios
Spring transaction failure scenarios
there is some reasons for failure scenarios in spring transaction.
- Using engine of database is not supported
- The class of transactional method is not managed by Spring (Usually unused annotation @Service)
- The transactional method is not public
- The class of transactional methods happend invoked its method ( the transactional of method should only invoke by Spring , or it will be no effect)
- The Transaction manager of datasource is not existed.(such as
@Transactional(propagation = Propagation.NOT_SUPPORTED)
) - The exception produced by the transaction of method was not thrown.
- The exception produced by the transaction of method was thrown , but its type is error. The exception should be a java Runtime Exception, if you want to make the transaction of method effect when throw other exception, then you should use follows
@Transactional(rollbackFor = Exception.class)