First, make sure that the @Transactional annotation is added to the calling method
1. Add the @Transactional annotation where transaction management is required. The @Transactional annotation can be applied to interface definitions and interface methods, class definitions and public methods of classes.
2. @Transactional annotations can only be applied to public visibility methods. If you use the @Transactional annotation on a protected, private, or package-visible method, it will not report an error, but the annotated method will not display the configured transaction settings.
3. Note that the mere presence of the @Transactional annotation is not sufficient to enable transactional behavior, it is only a metadata. You must use the configuration element in the configuration file to actually enable the transaction behavior. (spring configuration file, turn on declarative transactions)
The value of the “proxy-target-class” attribute of the element controls whether interface-based or class-based proxies are created. If the “proxy-target-class” property is set to “true”, then the class-based proxy will work (this requires the CGLIB library cglib.jar in the CLASSPATH). If the “proxy-target-class” property is set to “false” or if this property is omitted, then the standard JDK interface-based proxy will work.
5. The Spring team recommends using @Transactional annotations on specific classes (or methods of classes) and not on any interfaces that the class is intended to implement. Using @Transactional annotations on interfaces will only work if you set up an interface-based proxy. Because annotations are not inheritable, this means that if a class-based proxy is being used, then the transaction settings will not be recognized by the class-based proxy and the object will not be wrapped by the transaction proxy.
6. @Transactional transactions are opened, either by interface-based or class-based proxies are created. So in the same class a non-transactional method calls another transactional method, the transaction will not work.
Pay special attention to point 6: a non-transactional method in the same class calls another transactional method, the transaction will not work. This point caught my attention, maybe my annotated @Transactional departingCar method is also called by another method in the class that does not open a transaction, if this is true, everything makes sense.
- Error creating bean with name [How to Solve]
- Spring Project Error: Error creating bean with name [How to Solve]
- Mybatis reports an error (error building sqlsession.) when using annotations without deleting redundant files
- [Solved] In case of “transactionmanager” while setting bean property “transactionmanager” error
- Java error: java.lang.NoSuchMethodError
- How to Solve Tomcat Error: Could not resolve view with name ‘xxx/xxxxxxx‘ in servlet with
- [Solved] jar file Execute Error: power shell error: unable to access jarfile
- Java callback function implementation case
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- Springboot controls the startup of rabbitmq through configuration files
- Abstract method and static method of java interface
- [Solved] error: method does not override or implement a method from a supertype
- How to Solve Junit Unit Test Error: “No runnable methods“
- Mybatis Error: The error may exist in xxxxMapper.xml [How to Solve]
- [Solved] Initialization of anonymous inner class member variable causes java.lang.stackoverflowerror
- SpringCloud Use openFeign Multipartfile to Upload Files Error: Current request is not a multipart request
- [Solved] Idea Build error. The symbol — Lombok cannot be found
- Java Error: No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- Solve the use of declaration transactions in spring java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable
- How to Solve Swagger error: typeerror: failed to fetch