If you want to cancel the current transaction, you can use
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
Please note that it does not roll back the transaction immediately - it sets the status to "rollback only", so the transaction will be rolled back during a commit attempt.
Otherwise, if you need demarcation of software transactions, you can use TransactionTemplate, as described in 10.6 Software Transaction Management .You can also get an instance PlatformTransactionManager, but it is not widely used, since it TransactionTemplateis the recommended approach to programmatic transaction demarcation.
See also:
source
share