Stepping on the pit series "six" Spring increases transaction processing and encounters exception solutions

When adding, deleting and modifying data, transaction processing is needed, so the @Transactional annotation is added to the business layer, but an exception is encountered before the business operation is executed, so the exception is thrown, but the data is weird Saved to the database successfully.

Solution: The total exception is accurate to the specific exception, for example, the problem of changing Exception to RuntimeException can be solved. This is because Spring's AOP, or declarative transaction management, defaults to rollback for unchecked exceptions. That is, by default, the RuntimeException() exception or its subclasses are rolled back.

Guess you like

Origin blog.csdn.net/hyx1249273846/article/details/107322368