java – EJB3 / JPA @Transactional

Is there an EJB or JPA annotation equivalent to spring's @ transactional?

Solution

The equivalent EJB 3 attribute is javax ejb. TransactionAttribute.

Just like spring's @ transactional annotation, you can control transaction "propagation" by passing transactionattributetype to transactionattribute annotation, such as:

@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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>