InnoDB is the default storage engine for MySQL. InnoDB is a standard for MySQL AB to publish binary data. InnoDB was developed by Innobase Oy and acquired by Oracle in May 2006. Compared to traditional ISAM and MyISAM, InnoDB features acid-compliant Transaction functionality, similar to PostgreSQL. The default storage engine since MySQL 5.5.5 is InnoDB. The default storage engine before MySQL 5.5.5 is MyISAM, so it is worth noting that the underlying engine does not support transactions.

@transactional public class TestService {@transactional public void Test(Order Order) {// Update Order} } 1, 2, 3, 4, 5, 6, 7, 8, 9 This class would not be loaded as a Bean without the @service annotation. The class will not be managed by Spring, and the transaction will be invalidated.

1.4.6 Method visibility and @transactional When you use proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. If you need to annotate non-public Methods, consider using AspectJ (described later). 1 2 3 4 6 If you want to use it on non-public methods, you can turn on the AspectJ proxy mode.

@service public class OrderServiceImpl implements OrderService {public void update(Order Order) { updateOrder(order); } @transactional public void updateOrder(Order Order) {// updateOrder}} 12 3 4 5 6 7 8 9 10 11 12 13 Transactional transactions on the updateOrder method that have the @Transactional annotation do not take effect. @Service public class OrderServiceImpl implements OrderService { @Transactional public void update(Order order) { updateOrder(order); } @Transactional(propagation = Propagation.REQUIRES_NEW) public void updateOrder(Order order) { // update order } } 1 2 The Transactional update method with @transactional and the updateOrder method with REQUIRES_NEW will not work either. Call the class’s own methods because they make their own calls, not Spring’s proxy classes, and by default only invoke transactions externally.

5. The data source without the transaction manager @ Bean public PlatformTransactionManager transactionManager (DataSource DataSource) {return new DataSourceTransactionManager(dataSource); } 1 2 3 4 If the current data source is not configured with a transaction manager, this will not take effect either.

@transactional public class OrderServiceImpl implements OrderService {@transactional public void update(Order Order) { updateOrder(order); } @Transactional(propagation = Propagation.NOT_SUPPORTED) public void updateOrder(Order order) { // update order } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Propagation.NOT_SUPPORTED: It is not run as a transaction and is suspended if a transaction exists.

// @transactional public class OrderServiceImpl implements OrderService {@transactional public void UpdateOrder (Order Order) {try {// updateOrder} catch {}} 12 3 4 5 6 7 9 10 11 12 13

// @service public class OrderServiceImpl implements OrderService {@transactional public void UpdateOrder (Order Order) {try {// updateOrder} catch {throw new Exception(” update error “); }}} 12 3 4 5 6 7 8 9 10 11 12 13 @Transactional rolls back RuntimeException by default. Exception is the parent of RuntimeException. Transaction does not take effect. Transactional(rollbackFor = exception.class)

Original link: blog.csdn.net/qq_43399077…