EJB3 / JPA @Transactional [英] EJB3 / JPA @Transactional

查看:112
本文介绍了EJB3 / JPA @Transactional的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有相当于Spring的@Transactional的EJB或JPA注释?

Is there an EJB or JPA annotiation that is equivalent to Spring's @Transactional ?

推荐答案

等效的EJB3属性是 javax.ejb.TransactionAttribute

The equivalent EJB3 attribute is javax.ejb.TransactionAttribute.

就像Spring的 @Transactional 注释一样,您可以通过传递<$ c $来控制事务的传播 c> TransactionAttributeType 到 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() {...}
}

容器管理事务在 Java EE 5教程第四部分

这篇关于EJB3 / JPA @Transactional的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆