Compilation error when using @Transactional with distribution attribute

I developed a spring data processing program using this tutorial. Then modified it by adding a new class / method to check spring @Transactional annotation.

@Transactional public void txnMethod() { repository.save(new Customer("First Customer","")); repository.save(new Customer("Second Customer","")); ... } 

The above code has been compiled and executed correctly. Then I modified the code to explicitly set the distribution mode, as shown below, but it gives me a compilation error - "Distributing the undefined attribute for the Transactional annotation type"

 @Transactional(propagation=Propagation.REQUIRED) public void txnMethod() { repository.save(new Customer("First Customer","")); repository.save(new Customer("Second Customer","")); ... } 

How can I explicitly specify the distribution mode? Below are the dependencies in build.gradle. I'm using spring version for download 1.2.1.RELEASE

 dependencies { compile("org.springframework.boot:spring-boot-starter-jdbc") compile("org.springframework.boot:spring-boot-starter-data-jpa") compile("org.springframework.boot:spring-boot-starter-web") compile ("org.springframework.boot:spring-boot-starter-tomcat") compile("com.h2database:h2") providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") } 
+5
source share
1 answer

When working with applications that have a direct or transitive dependency on Spring Data, two classes named @Transactional are available in the compilation class path. One is javax.persistence.Transactional and the other is org.springframework.transaction.annotation.Transactional . This is a later class that should be used for declarative transaction management using Spring. Propagation enumeration is also supported only by a later class. The first supports another annotation called TxType .

Make sure that @Transactional type org.springframework.transaction.annotation.Transactional , as the IDE sometimes adds imports for javax.persistence.Transactional when the user types @Transactional . Then, trying to add Propagation to the annotation fails because javax.persistence.Transactional does not support this enumeration.

+9
source

Source: https://habr.com/ru/post/1214166/


All Articles