简体   繁体   中英

EJB3 / JPA @Transactional

是否存在与Spring的@Transactional等效的EJB或JPA注释?

The equivalent EJB3 attribute is javax.ejb.TransactionAttribute .

Just like Spring's @Transactional annotation, you can control the transaction 'propagation' by passing a TransactionAttributeType to the TransactionAttribute annotation, like:

@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 managed transactions are described in Part IV of the Java EE 5 Tutorial .

See javadoc on.

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

Namely the paragraph: See the EJB specification for restrictions on the use of @Transactional with EJBs.

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM