1 Reply Latest reply on Apr 18, 2007 10:06 AM by Matt Drees

    seam gen war on tomcat - @startup dependency problem

    Matt Drees Master

      I've been trying to get a war seam-gen project running on Tomcat, and I've been successful at getting the right jars, I believe. However, I am having problems with the EntityManagerFactory component starting before the embedded EJB container is started (which fails because the datasource isn't in jndi). It's strange because integration tests don't have any problems.

      I think the issue is the EntityManagerFactory component is declared to depend on the microcontainer, but not eejb.
      (its declaration for reference:)

      @Scope(ScopeType.APPLICATION)
      @Intercept(NEVER)
      @Startup(depends="org.jboss.seam.core.microcontainer")
      public class EntityManagerFactory
      


      I think during tests the ejb component is luckily started before the EMF component, but on tomcat it unluckily isn't. It seems like "org.jboss.seam.core.ejb" ought to be added to EntityManagerFacatory's startup dependency list.

      Does this sound reasonable?


      releveant components.xml:
       <core:managed-persistence-context name="entityManager"
       auto-create="true"
       entity-manager-factory="#{crsEntityManagerFactory}"/>
      
       <core:entity-manager-factory name="crsEntityManagerFactory"
       persistence-unit-name="crs"/>
      
       <core:ejb installed="@embeddedEjb@"/>
      


      log/stacktrace:
      11:55:21,268 INFO [Lifecycle] starting up: crsEntityManagerFactory
      11:55:21,393 INFO [Version] Hibernate EntityManager 3.2.0.CR1
      11:55:21,440 INFO [Version] Hibernate Annotations 3.2.0.CR1
      11:55:21,471 INFO [Environment] Hibernate 3.2 cr2
      ...more non-interesting EMF startup stuff...
      11:55:29,540 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
      11:55:29,619 ERROR [NamingHelper] Could not obtain initial context
      javax.naming.NamingException: Local server is not initialized
       at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
       at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
       at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
       at javax.naming.InitialContext.init(Unknown Source)
       at javax.naming.InitialContext.<init>(Unknown Source)
       at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
       at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
       at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
       at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
       at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
       at org.jboss.seam.core.EntityManagerFactory.startup(EntityManagerFactory.java:74)
       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:20)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
       at org.jboss.seam.Component.callComponentMethod(Component.java:1850)
       at org.jboss.seam.Component.callCreateMethod(Component.java:1765)
       at org.jboss.seam.Component.newInstance(Component.java:1754)
       at org.jboss.seam.contexts.Lifecycle.startup(Lifecycle.java:175)
       at org.jboss.seam.contexts.Lifecycle.endInitialization(Lifecycle.java:145)
       at org.jboss.seam.init.Initialization.init(Initialization.java:504)
       at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:33)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
       at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1175)
       at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:527)
       at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:104)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Unknown Source)
      11:55:29,650 FATAL [DatasourceConnectionProvider] Could not find datasource: java:/crsDatasource
      javax.naming.NamingException: Local server is not initialized
       at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
       at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
       at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
       at javax.naming.InitialContext.init(Unknown Source)
       at javax.naming.InitialContext.<init>(Unknown Source)
       at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
       at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
       at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
       at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
       at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
       at org.jboss.seam.core.EntityManagerFactory.startup(EntityManagerFactory.java:74)
       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:20)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
       at org.jboss.seam.Component.callComponentMethod(Component.java:1850)
       at org.jboss.seam.Component.callCreateMethod(Component.java:1765)
       at org.jboss.seam.Component.newInstance(Component.java:1754)
       at org.jboss.seam.contexts.Lifecycle.startup(Lifecycle.java:175)
       at org.jboss.seam.contexts.Lifecycle.endInitialization(Lifecycle.java:145)
       at org.jboss.seam.init.Initialization.init(Initialization.java:504)
       at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:33)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
       at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1175)
       at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:527)
       at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:104)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Unknown Source)
      11:55:29,650 ERROR [[/crs]] Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
      javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not find datasource
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:217)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
       at org.jboss.seam.core.EntityManagerFactory.startup(EntityManagerFactory.java:74)
       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:20)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
       at org.jboss.seam.Component.callComponentMethod(Component.java:1850)
       at org.jboss.seam.Component.callCreateMethod(Component.java:1765)
       at org.jboss.seam.Component.newInstance(Component.java:1754)
       at org.jboss.seam.contexts.Lifecycle.startup(Lifecycle.java:175)
       at org.jboss.seam.contexts.Lifecycle.endInitialization(Lifecycle.java:145)
       at org.jboss.seam.init.Initialization.init(Initialization.java:504)
       at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:33)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
       at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1175)
       at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:527)
       at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:104)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Unknown Source)
      Caused by: org.hibernate.HibernateException: Could not find datasource
       at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
       at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
       at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
       at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
       ... 38 more
      Caused by: javax.naming.NamingException: Local server is not initialized
       at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
       at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
       at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
       at javax.naming.InitialContext.init(Unknown Source)
       at javax.naming.InitialContext.<init>(Unknown Source)
       at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
       at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
       ... 47 more
      Apr 17, 2007 11:55:29 AM org.apache.catalina.core.StandardContext start
      SEVERE: Error listenerStart
      Apr 17, 2007 11:55:29 AM org.apache.catalina.core.StandardContext start
      SEVERE: Context [/crs] startup failed due to previous errors
      


      persistence.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0">
      
       <persistence-unit name="crs">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/crsDatasource</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="update"/>
       <property name="hibernate.cache.use_query_cache" value="true"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/crsEntityManagerFactory"/>
       </properties>
       </persistence-unit>
      
      </persistence>
      



      I got things working by using persistence-unit-jndi-name in components.xml, but I want to also be able to deploy to jboss as a war, which means I need to use the EntityManagerFactory component, as I understand it.

      Thanks for any feedback.