gpt4 book ai didi

java - EJB 3,同一 bean 中的事务流

转载 作者:行者123 更新时间:2023-11-30 04:09:12 24 4
gpt4 key购买 nike

如果我在 EJB bean 中有两个方法,其中一个的 Transaction 属性为 NOT_SUPPORTED,需要使用 REQUIRED 调用另一个,那么如果我通过注入(inject)的 bean 进行调用,我是否可以期望事务启动:

@Stateless
@LocalBean
public class LeBean {

@EJB LeBean bean;

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

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

或者我可以像这样在本地调用电话吗:

@Stateless
@LocalBean
public class LeBean {

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

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

现在 someMethod() 在到达 otherMethod() 之前需要很长时间来处理信息,因此事务超时,即使我已将 NOT_SUPPORTED 声明为 transactionAttribute对于第一种方法。

最佳答案

can i expect the transaction to kick in if i make the call through an injected bean:

如果您想要事务,则必须通过注入(inject)的 bean 进行调用。调用必须通过业务接口(interface)进行,否则您的交易属性将被忽略。在您的情况下,如果您从没有事务或暂停事务(即 NOT_SUPPORTED)的方法调用 otherMethod() ,那么它只是一个 POJO 调用。

从技术上讲, otherMethod() 将“骑在” someMethod() 的事务之上(如果确实存在)。例如,您对 someMethod() 具有 NOT_SUPPORTED,但如果它是 REQUIRED 或 REQUIRES_NEW,则 otherMethod() 将共享该事务。 someMethod() 的回滚也会回滚 otherMethod() 的操作。

right now someMethod() takes a long time to process information before reaching otherMethod() and so the transaction times out

这完全是一个不同的问题。您可能希望增加事务超时,并考虑将其作为单独的异步进程运行。

关于java - EJB 3,同一 bean 中的事务流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20039251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com