8 Replies Latest reply on Aug 30, 2010 2:00 PM by lrpieri

    TransactionManager deployment problem with Tomcat 6 (JNDI?)

    drivexcite.drivexcite.gmail.com

      Hi everybody,


      First of all, I found Seam an excellent piece of technology, so I decided to give it a chance as the main framework for my current project. I think, is currently the best alternative out there for web application development and I'm very pleased with the results I've got so far.


      I was using JBoss AS 5.0 as the development server, but just a few weeks ago, I was informed the final application will use Tomcat as the production environment.


      Naturally I tried to configure the new environment, but I failed because there is an exception that's raised while the application is deploying:


      2009-02-16 23:46:01,001 [main] WARN  net.sf.ehcache.hibernate.EhCacheProvider - Could not find a specific ehcache configuration for cache named [mx.gob.funcionpublica.siac.modelo.aseguramiento.ge.AtributoCalificadoGrupoEnfoque]; using defaults.
      2009-02-16 23:46:02,382 [main] INFO  org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
      2009-02-16 23:46:02,382 [main] INFO  org.hibernate.util.NamingHelper - JNDI InitialContext properties:{}
      16/02/2009 11:46:02 PM org.apache.catalina.core.StandardContext listenerStart
      GRAVE: Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
           at org.jboss.seam.Component.newInstance(Component.java:2066)
           at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
           at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
           at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:112)
           at org.jboss.seam.init.Initialization.init(Initialization.java:727)
           at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
           at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
           at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
           at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
           at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
           at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
           at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
           at org.apache.catalina.core.StandardService.start(StandardService.java:516)
           at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
           at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
           at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
      Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not locate TransactionManager
           at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:663)
           at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
           at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
           at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
           at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:81)
           at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:138)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2179)
           at org.jboss.seam.Component.callCreateMethod(Component.java:2094)
           at org.jboss.seam.Component.newInstance(Component.java:2054)
           ... 20 more
      Caused by: org.hibernate.HibernateException: Could not locate TransactionManager
           at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:26)
           at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:325)
           at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
           at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
           at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:656)
           ... 34 more
      Caused by: javax.naming.NameNotFoundException: Name TransactionManager is not bound in this Context
           at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
           at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
           at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
           at javax.naming.InitialContext.lookup(Unknown Source)
           at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:23)
           ... 38 more
      16/02/2009 11:46:02 PM org.apache.catalina.core.StandardContext start
      GRAVE: Error listenerStart
      16/02/2009 11:46:02 PM org.apache.catalina.core.StandardContext start
      GRAVE: Context [/SiacWeb] startup failed due to previous errors
      



      I really don't know what to do. I've already skimmed through the documentation (Sections 1.1.2 and 29.6.1, Seam 2.1.1GA). It's been almost a week and I'm still unable to run the application successfully.


      The relevant configuration is shown below (Seam 2.1.1GA, Tomcat 6.0.18):


      META-INF/context.xml (Tomcat 6 Context configuration):


      <Context path="/SiacWeb">
           <Resource name="jdbc/SiacWebDatasource" auth="Container"
                type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000"
                username="foouser" password="barpassword" driverClassName="com.mysql.jdbc.Driver"
                url="jdbc:mysql://localhost:3306/siac_db" />
      </Context>
      



      WEB-INF/classes/META-INF/hibernate.cfg.xml (Hibernate persistence provider configuration, excerpt):


      <hibernate-configuration>
           <session-factory>
                <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
      
                <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
           </session-factory>
      </hibernate-configuration>
      



      WEB-INF/classes/META-INF/persistence.xml (JPA deployment descriptor, excerpt):


      <persistence xmlns="..." version="1.0">
           <persistence-unit name="SiacWeb" transaction-type="RESOURCE_LOCAL">
                <jta-data-source>java:comp/env/jdbc/SiacWebDatasource</jta-data-source>
      
                <properties>
                     <property name="hibernate.ejb.cfgfile" value="META-INF/hibernate.cfg.xml" />
                </properties>
           </persistence-unit>
      </persistence>
      



      WEB-INF/web.xml (Web app deployment descriptor, excerpt):


      <web-app xmlns:xsi="..." version="2.5">
        <display-name>SiacWeb</display-name>
        <servlet>
          <servlet-name>Faces Servlet</servlet-name>
          <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
          <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
          <servlet-name>Faces Servlet</servlet-name>
          <url-pattern>*.seam</url-pattern>
        </servlet-mapping>
        <servlet>
          <servlet-name>Seam Resource Servlet</servlet-name>
          <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
        </servlet>
        <servlet-mapping>
          <servlet-name>Seam Resource Servlet</servlet-name>
          <url-pattern>/seam/resource/*</url-pattern>
        </servlet-mapping>
        <servlet>
             <servlet-name>Document Store Servlet</servlet-name>
          <servlet-class>org.jboss.seam.document.DocumentStoreServlet</servlet-class>
        </servlet>
        <servlet-mapping>
             <servlet-name>Document Store Servlet</servlet-name>
             <url-pattern>*.xls</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
          <servlet-name>Document Store Servlet</servlet-name>
          <url-pattern>*.pdf</url-pattern>
        </servlet-mapping>
        <listener>
          <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
        </listener>
        <filter>
          <filter-name>Seam Filter</filter-name>
          <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
        </filter>
        <filter-mapping>
          <filter-name>Seam Filter</filter-name>
          <url-pattern>/*</url-pattern>
        </filter-mapping>
        <resource-ref>
           <res-ref-name>jdbc/SiacWebDatasource</res-ref-name>
           <res-type>javax.sql.DataSource</res-type>
           <res-auth>Container</res-auth>
        </resource-ref>
      </web-app>
      



      WEB-INF/components.xml (Seam static components configuration, excerpt):


      <components xmlns="...">
           <core:init debug="true" jndi-pattern="#{ejbName}/local"/>     
      
           <persistence:managed-persistence-context
                name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}" />
      
           <persistence:entity-manager-factory
                name="entityManagerFactory" persistence-unit-name="SiacWeb" />
                     
           <transaction:entity-transaction entity-manager="#{entityManager}"/>          
      </components>
      
      



      I already tried to include Embedded JBoss, but I found a similar post where a user ASavitsky explains why Embedded JBoss is not necessary and recommends some configuration. Unfortunately that doesn't worked for me and here I am asking for some help...



      1. What other configuration is necessary to avoid this exception?

      2. Can you suggest me any other resource where I can find some information related to deploying Seam applications on Tomcat?

      3. Do you know any other thread in the forum where this problem is addressed and actually resolved?



      Your help would be really appreciated!
      Thanks!


      Further details (possibly useful):
      Ant build script: build.xml:


      <project name="SiacWeb" default="build" basedir=".">
           <fileset id="lib" dir="${lib.dir}">
                <include name="*.jar" />
           </fileset>
      
           <path id="build.classpath">
                <fileset refid="lib" />
           </path>
      
           <target name="compilemodel" description="Compile the Java source code" unless="eclipse.running">
                <mkdir dir="${dist.dir}" />
                <mkdir dir="${basedir}/exploded-archives" />
                <mkdir dir="${basedir}/exploded-archives/SiacWeb.war" />
                <mkdir dir="${basedir}/exploded-archives/SiacWeb.war/WEB-INF" />
                <mkdir dir="${basedir}/exploded-archives/SiacWeb.war/WEB-INF/classes" />
      
                <javac classpathref="build.classpath" destdir="${classes.model.dir}" debug="${javac.debug}" deprecation="${javac.deprecation}" nowarn="on">
                     <classpath refid="SiacWeb.classpath" />
                     <src path="${src.model.dir}" />
                </javac>
           </target>
      
           <target name="compileactions" depends="compilemodel" description="Compile the Java source code" unless="eclipse.running">
                <javac classpathref="build.classpath" destdir="${classes.action.dir}" debug="${javac.debug}" deprecation="${javac.deprecation}" nowarn="on">
                     <classpath path="${classes.model.dir}" />
                     <classpath refid="SiacWeb.classpath" />
                     <src path="${src.action.dir}" />
                </javac>
           </target>
      
           <target name="copyclasses" depends="compilemodel, compileactions" description="Copy the classes that were compiled by eclipse" if="eclipse.running">
                <copy todir="${classes.model.dir}">
                     <fileset dir="classes/model">
                          <include name="**/*.class" />
                     </fileset>
                </copy>
                <copy todir="${classes.action.dir}">
                     <fileset dir="classes/action">
                          <include name="**/*.class" />
                     </fileset>
                </copy>
           </target>
      
           <target name="compile" depends="compilemodel,compileactions,copyclasses" description="Compile the various source paths" />
      
           <target name="war" depends="compile" description="Build the WAR structure in a staging directory">
      
                <copy todir="${war.dir}/WEB-INF/classes">
                     <fileset dir="${basedir}/resources">
                          <include name="seam.properties" />
                          <include name="*.drl" />
                     </fileset>
                     <fileset dir="${src.model.dir}">
                          <include name="**/*.properties" />
                          <include name="**/*.xml" />
                          <include name="**/*.xsd" />
                          <include name="**/*.sql" />
                          <include name="**/*.drl" />
                     </fileset>
                     <fileset dir="${src.action.dir}">                    
                          <include name="**/*.xml" />
                     </fileset>
                </copy>
      
                <copy todir="${war.dir}">
                     <fileset dir="${webcontent.dir}" />
                </copy>
      
                <copy todir="${war.dir}/WEB-INF">
                     <fileset dir="${basedir}/web/WEB-INF">
                          <include name="*.*" />
                          <include name="classes/**/*.*" />
                          <exclude name="classes/**/*.class" />
                          <exclude name="classes/**/*.groovy" />
                     </fileset>
                </copy>
      
                <copy todir="${war.dir}/WEB-INF">
                     <fileset dir="${basedir}/web/WEB-INF">
                          <include name="lib/*.*" />
                          <include name="classes/**/*.class" />
                     </fileset>
                </copy>
      
                <copy todir="${war.dir}/WEB-INF/lib">
                     <fileset dir="${lib.dir}">
                          <exclude name="jboss-seam-gen.jar" />
                     </fileset>
                </copy>
      
                <copy todir="${war.dir}/WEB-INF/classes">
                     <fileset dir="${basedir}/resources">
                          <include name="**/*.xcss" />
                     </fileset>
                </copy>
      
                <copy todir="${war.dir}/WEB-INF/classes">
                     <fileset dir="${basedir}/resources">
                          <include name="messages*.properties" />
                          <include name="*.skin.properties" />
                          <include name="*_theme.properties" />
                     </fileset>
                </copy>
      
                <copy todir="${war.dir}/WEB-INF/classes">
                     <fileset dir="${basedir}/resources">
                          <include name="*jpdl.xml" />
                          <include name="*hibernate.cfg.xml" />
                          <include name="jbpm.cfg.xml" />
                          <include name="META-INF/orm.xml" />
                     </fileset>
                </copy>
           </target>
      
           <target name="stage" depends="war" />
      
           <target name="archive" depends="stage" description="Package the WAR archive">
                <jar jarfile="${dist.dir}/${project.name}.war" basedir="${war.dir}" />
           </target>
      </project>
      



        • 1. Re: TransactionManager deployment problem with Tomcat 6 (JNDI?)
          isaac01

          I suggest you to create a TransactionManager instance and put it in a JNDI Context as follows:



          <Context ...>
            ...
            <Resource name="TransactionManager" auth="Container"
                      type="com.arjuna.ats.jta.TransactionManager"
               description="TransactionManager"/>
            ...
          </Context>




          com.arjuna.ats.jta.TransactionManage class is included in jbossjta.jar


          So org.hibernate.transaction.JBossTransactionManagerLookup can find succesfully a Transactionmanager instance

          • 2. Re: TransactionManager deployment problem with Tomcat 6 (JNDI?)
            isaac01

            You coul'd also try this to allow user transaction in tomcat



            <Context ...>
              ...
              <Resource name="UserTransaction" auth="Container"
                type="javax.transaction.UserTransaction"/>
            
              <ResourceParams name="UserTransaction">
                <parameter>
                  <name>factory</name>
                  <value>org.hibernate.transaction.JTATransactionFactory</value>
                </parameter>    
              </ResourceParams>
            
              ...
            </Context>






            • 3. Re: TransactionManager deployment problem with Tomcat 6 (JNDI?)
              isaac01

              Also here is an UserTransaction JBoss impl com.arjuna.ats.jta.UserTransaction so also you shoul'd try tu use this instead of javax.transaction.UserTransaction  interface.

              • 4. Re: TransactionManager deployment problem with Tomcat 6 (JNDI?)
                isaac01


                com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple

                • 5. Re: TransactionManager deployment problem with Tomcat 6 (JNDI?)
                  drivexcite.drivexcite.gmail.com

                  Hi all,


                  Thank you very much for the tip Isaac, unfortunately I tried and didn't work.
                  However, I was finally able to start my application with Tomcat!


                  The only change that was made in order to run successfully, consisted in comment out the following line in hibernate.cfg.xml:


                  <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
                  



                  It seems the look up strategy used in JBoss AS is not compatible with the other one used in Tomcat. I just left unassigned the 'hibernate.transaction.managerlookupclass' property and it started without any exceptions.


                  Oh, maybe off-topic but I found the Rubber Ducking practice (described in The Pragmatic Programmer by Andrew Hunt and David Thomas) very useful in this case!!!

                  • 6. Re: TransactionManager deployment problem with Tomcat 6 (JNDI?)
                    nlevitt

                    I'm trying to port a seam webapp from jboss4 to tomcat and seeing this same error.


                    You say you removed this line from hibernate.cfg.xml:


                    <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
                    



                    I have that in WEB-INF/classes/META-INF/persistence.xml and I haven't tried removing it yet.


                    But the seam example jboss-seam-jpa built for tomcat6 includes that line in WEB-INF/classes/META-INF/persistence.xml as well. So it would seem that there is another way... but what?


                    • 7. Re: TransactionManager deployment problem with Tomcat 6 (JNDI?)
                      nlevitt

                      Er.. oops. That line is actually commented out in jboss-seam-jpa/WEB-INF/classes/META-INF/persistence.xml.
                      This seems relevant: http://seamframework.org/Community/SeamJPAExampleForTomcatJTA

                      • 8. Re: TransactionManager deployment problem with Tomcat 6 (JNDI?)
                        lrpieri

                        Hi All,


                        I'm trying to port a seam webapp from jboss 5 to tomcat 6.
                        When the context starts happend the follow error:


                        
                        Caused by: java.lang.IllegalArgumentException: Can not set static javassist.util.proxy.MethodFilter field br.com.xyz.reportbuilder.entity.DeviceModel_$$_javassist_20._method_filter to org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer$1
                             at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
                             at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
                             at sun.reflect.UnsafeStaticObjectFieldAccessorImpl.set(UnsafeStaticObjectFieldAccessorImpl.java:61)
                             at java.lang.reflect.Field.set(Field.java:657)
                             at javassist.util.proxy.ProxyFactory.setField(ProxyFactory.java:352)
                             ... 51 more
                        8179 [main] INFO impl.SessionFactoryObjectFactory  - Not binding factory to JNDI, no JNDI name configured



                        And when I try to loggin:




                        Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
                             at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
                             at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
                             at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
                             at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:92)
                             at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
                             ... 48 more
                        Caused by: java.lang.NullPointerException
                             at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
                             at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
                             at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
                             at java.sql.DriverManager.getDriver(DriverManager.java:253)
                             at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
                             ... 52 more



                        Does anybody have any idea about what is wrong/


                        Tks!!