gpt4 book ai didi

transactions - 从 JBoss 7 迁移到 WildFly 9 时使用 CMT 的 EJB

转载 作者:行者123 更新时间:2023-12-04 12:27:27 25 4
gpt4 key购买 nike

我正在将我的应用程序从 JBoss 7 迁移到 WildFly (v9.0.1),但由于 bean 事务管理错误而未部署。

    Caused by: javax.naming.NamingException: WFLYNAM0062: Failed to lookup env/com.component.eventmgt.EventServiceImpl/transaction [Root exception is java.lang.RuntimeException: WFLYNAM0059: Resource lookup for injection failed: java:jboss/UserTransaction]
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:157)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:83)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
at org.jboss.as.naming.deployment.ContextNames$BindInfo$1$1.getReference(ContextNames.java:316)
... 90 more
Caused by: java.lang.RuntimeException: WFLYNAM0059: Resource lookup for injection failed: java:jboss/UserTransaction
at org.jboss.as.naming.deployment.ContextNames$BindInfo$1$1.getReference(ContextNames.java:319)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:143)
... 95 more
Caused by: javax.naming.NameNotFoundException: UserTransaction [Root exception is java.lang.IllegalStateException: WFLYEJB0137: Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction]
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:153)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:83)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
at org.jboss.as.naming.deployment.ContextNames$BindInfo$1$1.getReference(ContextNames.java:316)
... 96 more

这是 EventServiceImpl 类。
    @Stateless
@Remote(EventService.class)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class EventServiceImpl implements EventService {

/**
* Logger
*/
private static Logger log = LoggerFactory.getLogger(EventService.class);

private EventTableDAO eventDao;

@PersistenceContext(unitName = "SOMF-GT")
private EntityManager entityManager;

@Resource
private UserTransaction transaction;

public List<Map> loadEvents() throws EventsException {

Configuration configurationEntry = new Configuration();
try {
Map configuration = configurationService.getConfiguration();
if (configuration != null) {

eventDao = new EventTableDAO(Event.class, entityManager, transaction);
List<Map> eventsMapList = new ArrayList();
}
}

我知道,如果我使用 @TransactionManagement(TransactionManagementType.BEAN) 将事务管理更改为 BMT,但是会出现以下错误

WFLYJPA0060: Transaction is required to perform this operation (either use a transaction or extended persistence context)



我想知道为什么我们首先要改变这一点?

任何信息,请!

最佳答案

这些更改在 Wildfly 8 中推出,并且(如下所述)基于 EJB 3.1 中全局 JNDI 命名空间的标准化。
来自野蝇 8 Developer Guide :

EJB 3.1 introduced a standardized global JNDI namespace and a series of related namespaces that map to the various scopes of a Java EE application. The three JNDI namespaces used for portable JNDI lookups are java:global, java:module, and java:app. If you use JNDI lookups in your application, you will need to change them to follow the new standardized JNDI namespace convention.

To conform to the new portable JNDI namespace rules, you will need to review the JNDI namespace rules and modify the application code to follow these rules.


该指南进一步指出:

WildFly 8 has tightened up on JNDI namespace names to provide predictable and consistent rules for every name bound in the application server and to prevent future compatibility issues. This means you might run into issues with the current namespaces in your application if they don't follow the new rules.


这是表格中的一个片段,显示 Examples of JNDI mappings in previous releases and how they might look now专用于 UserTransaction :
Previous Namespace          New Namespaces
------------------ --------------
java:comp/UserTransaction java:comp/UserTransaction (This will not be accessible for non EE threads, e.g. Threads your application directly creates)
java:comp/UserTransaction java:jboss/UserTransaction (Globally accessible, use this if java:comp/UserTransaction is not available)

编辑回复:WFLYEJB0137:
这是理论工艺,可能毫无值(value) - 让我知道,我会删除它。 Java EE 6 Tutorial - Container-Managed Transactions说:

Enterprise beans that use container-managed transaction demarcation also must not use the javax.transaction.UserTransaction interface.


更远:

(Transaction) Required Attribute

If the client is running within a transaction and invokes the enterprise bean’s method, the method executes within the client’s transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method.

The Required attribute is the implicit transaction attribute for all enterprise bean methods running with container-managed transaction demarcation. You typically do not set the Required attribute unless you need to override another transaction attribute. Because transaction attributes are declarative, you can easily change them later.


异常消息几乎说明了一切:

WFLYEJB0137: Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction


您的 EJB 正在使用容器管理事务 (CMT) 分界,它不与 bean 管理事务 (BMT) 分界互操作,其中 UserTransaction谎言。
关于转向 BMT 和

WFLYJPA0060: Transaction is required to perform this operation (either use a transaction or extended persistence context)


我找到了 Transaction is required to perform this operation (either use a transaction or extended persistence context)正如您在@Marco 的评论中指出的那样,这似乎表明交易将由您管理。看来您已经进行了适当的修改。

关于transactions - 从 JBoss 7 迁移到 WildFly 9 时使用 CMT 的 EJB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50491953/

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