gpt4 book ai didi

jakarta-ee - EJB 事务中的默认属性

转载 作者:行者123 更新时间:2023-12-03 23:49:08 24 4
gpt4 key购买 nike

我正在阅读 java ee docs我想问几个问题,以确保我已经很好地理解了 EJB-Transactions 发生了什么。

1) 文档指出默认 TransactionManagement值为 CONTAINER和默认 TransactionAttribute值为 REQUIRED :如果是这样,我对以下( session )Bean 使用 CONTAINER 执行其所有方法是否正确?托管事务和属性 REQUIRED ?

@Stateless
public class MyBean{

public void methodA(){
...
}

public void methodB(){
...
}

}

2)文档状态: Container-managed transactions do not require all methods to be associated with transactions. When developing a bean, you can set the transaction attributes to specify which of the bean’s methods are associated with transactions.
但是,如果我省略了 TransactionAttributeType ,是不是自动设置为 REQUIRED ?是 methodB在以下 Bean 中与事务无关?
@Stateless
@TransactionManagement(CONTAINER)
public class MyBean{

@TransactionAttribute(MANDATORY)
public void methodA(){
...
}

public void methodB(){
...
}

}

最佳答案

  • 是的,CONTAINERREQUIRED是默认值。
  • 您给出的报价似乎来自 The Java EE 5 Tutorial .我同意这句话的措辞有些困惑。这是可能有帮助的可能重写。

  • Container-managed transactions do not require all methods to use the default REQUIRED transaction semantics. When developing a bean, you can change the transaction semantics by setting the transaction attributes. For example, you can specify that a method should run without any transaction by using the NEVER transaction attribute,

    关于jakarta-ee - EJB 事务中的默认属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20860079/

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