Use Transactional annotation is not rolled back when using Spring, generally these may be the following reasons:
-
Check your method is not public.
-
Your type is not abnormal unchecked exceptions.
I want to check if an exception would also like to roll back how to do, annotations above stated exception type can be.
@Transactional (rollbackFor = Exception.class)
There are similar norollbackFor, custom exception does not roll back. -
To support transactional database engine, if it is mysql, pay attention to the table to use engine support services, such as innodb, if it is myisam, the transaction does not work.
-
Whether to open the parsing of annotations
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
- Scan this spring whether to your package, the following is scanned org.test following package
<context:component-scan base-package="org.test" ></context:component-scan>
These are the situations that may arise think, have the add.