Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Trying to migrate my Ejb from JBoss 7.1.1 to Wildfly, but I got stuck at the following error:

Caused by: org.springframework.transaction.TransactionSystemException: JTA UserTransaction is not available at JNDI location [java:jboss/UserTransaction]; nested exception is 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.springframework.transaction.jta.JtaTransactionManager.lookupUserTransaction(JtaTransactionManager.java:574)
    at org.springframework.transaction.jta.JtaTransactionManager.initUserTransactionAndTransactionManager(JtaTransactionManager.java:448)
    at org.springframework.transaction.jta.JtaTransactionManager.afterPropertiesSet(JtaTransactionManager.java:435)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
    ... 183 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:184)
    at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:237)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
    at org.springframework.transaction.jta.JtaTransactionManager.lookupUserTransaction(JtaTransactionManager.java:571)
    ... 187 more
Caused by: java.lang.IllegalStateException: WFLYEJB0137: Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction
    at org.jboss.as.ejb3.component.allowedmethods.AllowedMethodsInformation.realCheckPermission(AllowedMethodsInformation.java:138)
    at org.jboss.as.ejb3.component.allowedmethods.AllowedMethodsInformation.checkAllowed(AllowedMethodsInformation.java:112)
    at org.jboss.as.ejb3.subsystem.EJB3UserTransactionAccessControlService$1.authorizeAccess(EJB3UserTransactionAccessControlService.java:53)
    at org.jboss.as.txn.service.UserTransactionAccessControlService.authorizeAccess(UserTransactionAccessControlService.java:83)
    at org.jboss.as.txn.service.UserTransactionBindingService$1.getReference(UserTransactionBindingService.java:71)
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:143)
    ... 200 more

Spring 4 and transaction manager bean is set to JTA, as you can see below:

@Bean
public PlatformTransactionManager transactionManager(JndiTemplate jnditemplate) {
    // Get JTA from Java EE server
    final JtaTransactionManager jtaTransactionManager = new JtaTransactionManager();
    jtaTransactionManager.setTransactionManagerName("java:jboss/TransactionManager");
    jtaTransactionManager.setUserTransactionName("java:jboss/UserTransaction");
    jtaTransactionManager.setNestedTransactionAllowed(true);
    jtaTransactionManager.setJndiTemplate(jnditemplate);

    return jtaTransactionManager;
}

The Ejb's uses the following annotations

@Singleton
@Interceptors(SpringBeanAutowiringInterceptor.class)
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)

Anyone have any idea what's going on?

like image 842
Carlos Alberto Avatar asked Jun 17 '15 15:06

Carlos Alberto


1 Answers

Well, it's just what the exception message is saying:

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

You just can't use UserTransaction in an EJB, unless you add @TransactionManagement(javax.ejb.TransactionManagementType.BEAN).

Besides, what's the point of using Spring transactions anyway, when you're on WildFly with JTA, EJBs and @javax.transaction.Transactional for CDI beans at your disposal?

like image 55
Harald Wellmann Avatar answered Nov 06 '22 02:11

Harald Wellmann