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.
Read More:
- Failed to auto-configure a DataSource: ‘spring.datasource.url‘ is not specified and no embedded data
- [How to Fix]Spring 3.0 could not find acceptable representation
- Spring Cloud Hoxton.SR9 gateway and reactor-netty 0.9.0.RELEASE is Incompatible [How to Solve]
- Eclipse relies on spring boot configuration processor, and there is no prompt for writing properties and YML
- [Solved] spring source code compile error: target package does not exist
- [Solved] Solr8 establishes the cluster node as active, but the query reports an error
- [Solved] Hibernate Error: Row was updated or deleted by another transaction
- [Solved] Spring Kafka Send Error in specifies partition: Topic radar not present in metadata after 60000
- [Solved] ‘build.plugins.plugin.version‘ for org.springframework.boot:spring-boot-maven-plugin is missing.
- Spring Project Error: Error creating bean with name [How to Solve]
- [Solved] error running ‘xx‘ Command line is too long shorten command line for xx or also for Spring Boot defa
- [Solved] Kafka Error: is/are not present and missingTopicsFatal is true
- Spring integrated HBase error [How to Solve]
- Spring interdependence error: beancurrentyincreationexception unsatisfieddependencyexception
- Spring project import @Resource Annotation Error [How to Solve]
- Mongodb java version 3.X, prompt “XXX (an encryption algorithm) is not available” when there is a user name and password
- Solve the use of declaration transactions in spring java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable
- Annotation @resource & @Autowired introduces Spring bean error
- [Solved] Spring AOP Error creating bean with name
- [Solved] Failed to bind properties under ‘spring.servlet.multipart.file-size-threshold‘ to