EJB3 / JPA @Transactional

Is there an EJB or JPA annotation equivalent to Spring @Transactional?

+6
source share
2 answers

The EJB3 attribute is equivalent to javax.ejb.TransactionAttribute .

Like the Spring @Transactional annotation, you can control the propagation of the transaction by passing the TransactionAttributeType to the TransactionAttributeType annotation, for example:

 @TransactionAttribute(NOT_SUPPORTED) @Stateful public class TransactionBean implements Transaction { ... @TransactionAttribute(REQUIRES_NEW) public void firstMethod() {...} @TransactionAttribute(REQUIRED) public void secondMethod() {...} public void thirdMethod() {...} public void fourthMethod() {...} } 

Container-driven operations are described in Part IV of the Java EE 5 Tutorial .

+8
source

See javadoc on.

http://docs.oracle.com/javaee/7/api/javax/transaction/Transactional.html

Namely: See the EJB Specification for restrictions on using @Transactional with EJB.

I did not find any link to conditioning on this support in EJB 3.2.

http://www.oracle.com/technetwork/java/javaee/tech/index-jsp-142185.html

However, I am in weblogic 12.1.2 EJB 3.1 - the @Transactional attribute works on @Stateless @Local ejbs, which you inject into the base class using the CDI @Inject annotation.

In any case, I would not use the @Transactional annotation for the EJB, even if all of your EJBs are local and you enter them all using @Inject instead of @EJB. I would continue to use @TransactionAttribute with EJB.

+2
source

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


All Articles