12 Replies Latest reply on Aug 11, 2015 4:06 AM by alexlllleee

    jboss 4 -> wildfly 9 migration

    alexlllleee

      Hi!

       

      I have a task to migrate old app to a new wildfly 9.

      This app is based on spring framework 3.2.5.RELEASE.

       

      it have hibernate.cfg.xml file with transaction used as JTA

      <!-- Current session context is bound to a jta (transaction) -->
      <property name="current_session_context_class">jta</property>
       
      <!-- Auto sets to after_statement in jta -->
      <property name="hibernate.connection.release_mode">auto</property>

      <!-- Transaction factory -->
      <property name="hibernate.transaction.factory_class">
         org.hibernate.transaction.JTATransactionFactory

      </property>

      <!-- Binds userTransaction to jndi -->
      <property name="jta.UserTransaction">java:comp/UserTransaction</property>

      <!-- Transaction manager lookup -->
      <property name="hibernate.transaction.manager_lookup_class">
         org.hibernate.transaction.JBossTransactionManagerLookup

      </property>

       

      With jboss 4 it works fine. But for wildfly 9 it gives me error:

      org.hibernate.HibernateException: Unable to locate current JTA transaction

       

      please help! What needs to be done to make it work?

        • 1. Re: jboss 4 -> wildfly 9 migration
          tomekadamski

          Hi Alex,

          Can you paste the whole stacktrace?

           

          Tomek

          • 2. Re: jboss 4 -> wildfly 9 migration
            alexlllleee

            Sure

             

            org.hibernate.HibernateException: Unable to locate current JTA transaction

              at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:88)

              at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024)

              at org.playindustries.hibernate.util.HibernateUtil.currentSession(HibernateUtil.java:36)

              at org.playindustries.validators.NewPersonValidator.validateUserName(NewPersonValidator.java:203)

              at org.playindustries.spring.controllers.NewPersonController.handleRequestInternal(NewPersonController.java:40)

              at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)

              at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)

              at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)

              at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

              at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

              at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)

              at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

              at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

              at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

              at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)

              at org.playindustries.hibernate.util.HibernateSessionFilter.doFilter(HibernateSessionFilter.java:51)

              at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

              at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)

              at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

              at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)

              at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

              at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

              at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

              at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

              at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

              at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)

              at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

              at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

              at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)

              at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)

              at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)

              at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

              at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

              at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

              at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)

              at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)

              at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)

              at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)

              at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)

              at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

              at java.lang.Thread.run(Thread.java:745)

            • 3. Re: jboss 4 -> wildfly 9 migration
              tomekadamski

              Hi Alex,

              Please create your own TransactionManagerLookup class like this:

               

              package your.package;
              
              import java.util.Properties;
              import javax.naming.InitialContext;
              import javax.naming.NamingException;
              import javax.transaction.Transaction;
              import javax.transaction.TransactionManager;
              import org.hibernate.HibernateException;
              import org.hibernate.transaction.TransactionManagerLookup;
              
              
              public class TransactionManagerLookupImpl implements TransactionManagerLookup {
                  public Object getTransactionIdentifier(Transaction transaction) {
                      return transaction;
                  }
                  public TransactionManager getTransactionManager(Properties properties) throws HibernateException {
                      try {
                          return (TransactionManager) new InitialContext()
                                  .lookup("java:TransactionManager");
                      } catch (NamingException e) {
                          throw new RuntimeException(e);
                      }
                  }
                  public String getUserTransactionName() {
                      return null;
                  }
              }
              

               

              and the refer to it from the configuration:

               

              <property name="hibernate.transaction.manager_lookup_class"
                value="your.package.TransactionManagerImpl" />
              


                }
              Tomek

              • 4. Re: jboss 4 -> wildfly 9 migration
                alexlllleee

                Tomek, thank you for replay!

                 

                Now it shows me this error:

                java.lang.RuntimeException: javax.naming.NameNotFoundException: java:TransactionManager

                  at org.playindustries.util.TransactionManagerLookupImpl.getTransactionManager(TransactionManagerLookupImpl.java:21)

                  at org.hibernate.service.jta.platform.internal.TransactionManagerLookupBridge.locateTransactionManager(TransactionManagerLookupBridge.java:48)

                  at org.hibernate.service.jta.platform.internal.AbstractJtaPlatform.retrieveTransactionManager(AbstractJtaPlatform.java:88)

                  at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:79)

                  at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024)

                  at org.playindustries.hibernate.util.HibernateUtil.currentSession(HibernateUtil.java:36)

                  at org.playindustries.validators.NewPersonValidator.validateUserName(NewPersonValidator.java:203)

                  at org.playindustries.spring.controllers.NewPersonController.handleRequestInternal(NewPersonController.java:40)

                  at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)

                  at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)

                  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)

                  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

                  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

                  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)

                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

                  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

                  at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)

                  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)

                  at org.playindustries.hibernate.util.HibernateSessionFilter.doFilter(HibernateSessionFilter.java:51)

                  at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

                  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

                  at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)

                  at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

                  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

                  at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)

                  at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

                  at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

                  at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

                  at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                  at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

                  at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

                  at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                  at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)

                  at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

                  at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

                  at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)

                  at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)

                  at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)

                  at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

                  at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)

                  at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                  at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

                  at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                  at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                  at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)

                  at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)

                  at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)

                  at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)

                  at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)

                  at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)

                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

                  at java.lang.Thread.run(Thread.java:745)

                Caused by: javax.naming.NameNotFoundException: java:TransactionManager

                  at org.jboss.as.naming.InitialContext$DefaultInitialContext.findContext(InitialContext.java:189)

                  at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:233)

                  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.playindustries.util.TransactionManagerLookupImpl.getTransactionManager(TransactionManagerLookupImpl.java:19)

                  ... 53 more

                • 5. Re: jboss 4 -> wildfly 9 migration
                  tomekadamski

                  Sorry I made a typo in the code. Please change the name to: "java:/TransactionManager"

                   

                  Tomek

                  • 6. Re: jboss 4 -> wildfly 9 migration
                    alexlllleee

                    Tomek, now it prints:

                     

                    org.hibernate.HibernateException: Unable to locate current JTA transaction

                      at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:88)

                      at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024)

                      at org.playindustries.hibernate.util.HibernateUtil.currentSession(HibernateUtil.java:36)

                      at org.playindustries.validators.NewPersonValidator.validateUserName(NewPersonValidator.java:203)

                      at org.playindustries.spring.controllers.NewPersonController.handleRequestInternal(NewPersonController.java:40)

                      at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)

                      at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)

                      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)

                      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:867)

                      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)

                      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)

                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

                      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)

                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

                      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)

                      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)

                      at org.playindustries.hibernate.util.HibernateSessionFilter.doFilter(HibernateSessionFilter.java:51)

                      at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

                      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

                      at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)

                      at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

                      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

                      at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)

                      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

                      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

                      at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

                      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                      at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

                      at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

                      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                      at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)

                      at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

                      at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

                      at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)

                      at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)

                      at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)

                      at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

                      at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)

                      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                      at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

                      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                      at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)

                      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)

                      at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)

                      at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)

                      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)

                      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)

                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

                      at java.lang.Thread.run(Thread.java:745)

                    • 7. Re: jboss 4 -> wildfly 9 migration
                      smarlow

                      Note that the tm name changed.  See org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform:

                       

                      public static final String AS7_TM_NAME = "java:jboss/TransactionManager";
                      public static final String AS4_TM_NAME = "java:/TransactionManager";
                      

                       

                      You will want to use "java:jboss/TransactionManager"


                       

                      • 8. Re: jboss 4 -> wildfly 9 migration
                        alexlllleee

                        the same error even with "java:jboss/TransactionManager":

                        org.hibernate.HibernateException: Unable to locate current JTA transaction

                        • 9. Re: jboss 4 -> wildfly 9 migration
                          tomekadamski

                          Hi Alex,

                          How do you start your transaction?

                          Do you have an hibernate lib bundled inside your application?

                           

                          Tomek

                          • 10. Re: jboss 4 -> wildfly 9 migration
                            alexlllleee

                            Tomek, Scott, thank you for all your help!


                            I resolved my issue with adding @Transactional annotations everywhere :-)

                            • 11. Re: jboss 4 -> wildfly 9 migration
                              stoyanpetrov

                              Hi Alex, is it possible to post your full solution

                              Thanks!

                              • 12. Re: jboss 4 -> wildfly 9 migration
                                alexlllleee

                                My project was old and it had old libs as dependencies so I updated them because even maven was unable to find old versions.

                                First of all, you need to find a good Spring <--> Hibernate combination because Spring 3.2 + hibernate 4.3 - not working.

                                These versions are working good for me:

                                <hibernate.version>4.2.20.Final</hibernate.version>
                                <spring.version>4.0.9.RELEASE</spring.version>

                                Then, you need to add @Transactional annotations on your services. (in jboss 4 it was working without these annotations, probably because spring was older).

                                And finally you need to configure transaction manager, datasource and session factory in spring configuration (search the internet there are a lot of examples)