简体   繁体   English

EJB 3,同一bean中的事务流

[英]EJB 3, Transaction flow in same bean

If i have two methods inside an EJB bean, one with Transaction attribute of NOT_SUPPORTED that needs to call the other with REQUIRED, can i expect the transaction to kick in if i make the call through an injected bean: 如果我在EJB Bean中有两个方法,一个具有NOT_SUPPORTED事务属性的事务,该方法需要用REQUIRED调用另一个方法,那么如果我通过注入的Bean进行调用,我是否可以期望事务启动:

@Stateless
@LocalBean
public class LeBean {

    @EJB LeBean bean;

    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public void someMethod(){
        ...
        bean.otherMethod();
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void otherMethd(){
        ...
    }
}

or can i make the call locally like so: 或者我可以像这样在本地拨打电话:

@Stateless
@LocalBean
public class LeBean {

    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public void someMethod(){
        ...
        otherMethod();
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void otherMethd(){
        ...
    }
}

right now someMethod() takes a long time to process information before reaching otherMethod() and so the transaction times out, even though i have stated NOT_SUPPORTED as the transactionAttribute for the first method. 现在,即使我已经声明NOT_SUPPORTED作为第一个方法的transactionAttribute, someMethod()在到达otherMethod()之前需要花费很长时间来处理信息,因此事务超时。

can i expect the transaction to kick in if i make the call through an injected bean: 如果我通过注入的bean进行调用,我可以期望事务启动吗?

You HAVE to make the call through the injected bean if you want a transaction. 如果您要进行交易,则必须通过注入的Bean进行调用。 The calls have to be made through the business interface, or else your transaction attribute will be ignored. 调用必须通过业务接口进行,否则您的交易属性将被忽略。 In your case if you call otherMethod() from a method that has no transaction, or a suspended transaction (ie - NOT_SUPPORTED) then it is simply a POJO call. 在您的情况下,如果从没有事务或挂起的事务(即-NOT_SUPPORTED)的方法中调用otherMethod(),则它只是一个POJO调用。

Technically speaking otherMethod() will "ride on top of" the transaction of someMethod() if one did exist. 从技术上讲,如果某方法确实存在,otherMethod()将“置于someMethod()的事务之上”。 For example you have NOT_SUPPORTED for someMethod(), but if it were REQUIRED or REQUIRES_NEW, then otherMethod() would share in that transaction. 例如,对于someMethod(),您具有NOT_SUPPORTED,但是如果它是REQUIRED或REQUIRES_NEW,则otherMethod()将在该事务中共享。 A rollback for someMethod() would also rollback operations from otherMethod(). 回退someMethod()也会回退otherMethod()的操作。

right now someMethod() takes a long time to process information before reaching otherMethod() and so the transaction times out 现在someMethod()在到达otherMethod()之前需要花费很长时间来处理信息,因此事务超时

That is a different issue altogether. 这完全是另一个问题。 You may wish to increase your transaction timeout, and consider running this as a separate asynchronous process. 您可能希望增加事务超时,并考虑将其作为单独的异步过程运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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