2

After migrating to Java 8 and WildFly 8.2.0 I get this error on every Transaction

UserTransaction: javax.naming.NameNotFoundException: UserTransaction [Root exception is java.lang.IllegalStateException: JBAS014237: 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:140) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:81) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179) at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:188) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184) at javax.naming.InitialContext.lookup(InitialContext.java:417) [rt.jar:1.8.0_45] at javax.naming.InitialContext.lookup(InitialContext.java:417) [rt.jar:1.8.0_45]

The Bean has the annotation @TransactionManagement(TransactionManagementType.BEAN)

This is where the exception happens:

final javax.naming.Context tmpNamingContext = new javax.naming.InitialContext();
                    userTransaction = ((UserTransaction) tmpNamingContext.lookup("java:jboss/UserTransaction"));

I don't know what is happening here and cannot found any good solution.

Please help.

Johnny2012
  • 1,512
  • 8
  • 31
  • 46

1 Answers1

2

Get the UserTransaction with the annotation @Resource instead of through the JNDI Name was the solution. UserTransaction is no more in WildFly 8.2.0, in JBoss it was set already.

This solves the issue.

Johnny2012
  • 1,512
  • 8
  • 31
  • 46
  • I am also getting the same exception, when i call my api only through ejb call (i.e. from Web Services/Rest Services it is working) and the api has Event.fire() which is causing the issue, No idea why? Any help will be highly appreciated. I am using Container Managed Transaction with widlfly 10.1.0 – Krishna Sep 26 '18 at 14:53