0 Replies Latest reply on Oct 16, 2010 8:55 AM by Karsten Wutzke

    Configuring persistence unit (Tomcat 6, Embedded JBoss): javax.naming.NameNotFoundException: Name java:comp is not bound in this Context

    Karsten Wutzke Expert

      OK it all started out with


      http://seamframework.org/Community/ComponentNotInstantiated


      which was solved. When components using EntityQuery are instantiated I get the following exception:


      javax.servlet.ServletException: Could not instantiate Seam component: seasonListQuery
          javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
      
      root cause
      
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: seasonListQuery
          org.jboss.seam.Component.newInstance(Component.java:2144)
          org.jboss.seam.Component.getInstance(Component.java:2021)
          org.jboss.seam.Component.getInstance(Component.java:1983)
          org.jboss.seam.Component.getInstance(Component.java:1977)
          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
          org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
          org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
          javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
          com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
          org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
          org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
          org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
          com.sun.facelets.el.ELText$ELTextVariable.toString(ELText.java:174)
          com.sun.facelets.el.ELText$ELTextComposite.toString(ELText.java:115)
          com.sun.facelets.compiler.CommentInstruction.write(CommentInstruction.java:38)
          com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
          com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
          javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
          com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
          com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
          com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
          com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
          javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
      
      root cause
      
      java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:comp/env/bbstatsEntityManagerFactory
          org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:245)
          org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:78)
          org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:107)
          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          java.lang.reflect.Method.invoke(Unknown Source)
          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
          org.jboss.seam.Component.callComponentMethod(Component.java:2249)
          org.jboss.seam.Component.unwrap(Component.java:2275)
          org.jboss.seam.Component.getInstance(Component.java:2041)
          org.jboss.seam.Component.getInstance(Component.java:1983)
          org.jboss.seam.Component.getInstance(Component.java:1977)
          org.jboss.seam.Component.getInstance(Component.java:1972)
          org.jboss.seam.framework.Controller.getComponentInstance(Controller.java:272)
          org.jboss.seam.framework.PersistenceController.getPersistenceContext(PersistenceController.java:20)
          org.jboss.seam.framework.EntityQuery.getEntityManager(EntityQuery.java:159)
          org.jboss.seam.framework.EntityQuery.validate(EntityQuery.java:39)
          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          java.lang.reflect.Method.invoke(Unknown Source)
          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
          org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
          org.jboss.seam.util.Work.workInTransaction(Work.java:47)
          org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
          org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
          org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
          com.kawoolutions.bbstats.semidao.SeasonListQuery_$$_javassist_seam_2.validate(SeasonListQuery_$$_javassist_seam_2.java)
          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          java.lang.reflect.Method.invoke(Unknown Source)
          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
          org.jboss.seam.Component.callComponentMethod(Component.java:2249)
          org.jboss.seam.Component.callCreateMethod(Component.java:2172)
          org.jboss.seam.Component.newInstance(Component.java:2132)
          org.jboss.seam.Component.getInstance(Component.java:2021)
          org.jboss.seam.Component.getInstance(Component.java:1983)
          org.jboss.seam.Component.getInstance(Component.java:1977)
          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
          org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
          org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
          javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
          com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
          org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
          org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
          org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
          com.sun.facelets.el.ELText$ELTextVariable.toString(ELText.java:174)
          com.sun.facelets.el.ELText$ELTextComposite.toString(ELText.java:115)
          com.sun.facelets.compiler.CommentInstruction.write(CommentInstruction.java:38)
          com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
          com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
          javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
          com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
          com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
          com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
          com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
          javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
      
      root cause
      
      javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
          org.apache.naming.NamingContext.lookup(NamingContext.java:770)
          org.apache.naming.NamingContext.lookup(NamingContext.java:153)
          org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
          org.jboss.embedded.tomcat.jndi.ENCFactory.getObjectInstance(ENCFactory.java:74)
          javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
          javax.naming.spi.NamingManager.getContext(Unknown Source)
          javax.naming.spi.ContinuationContext.getTargetContext(Unknown Source)
          javax.naming.spi.NamingManager.getContinuationContext(Unknown Source)
          org.jnp.interfaces.NamingContext.lookup(NamingContext.java:775)
          org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
          javax.naming.InitialContext.lookup(Unknown Source)
          org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:241)
          org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:78)
          org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:107)
          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          java.lang.reflect.Method.invoke(Unknown Source)
          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
          org.jboss.seam.Component.callComponentMethod(Component.java:2249)
          org.jboss.seam.Component.unwrap(Component.java:2275)
          org.jboss.seam.Component.getInstance(Component.java:2041)
          org.jboss.seam.Component.getInstance(Component.java:1983)
          org.jboss.seam.Component.getInstance(Component.java:1977)
          org.jboss.seam.Component.getInstance(Component.java:1972)
          org.jboss.seam.framework.Controller.getComponentInstance(Controller.java:272)
          org.jboss.seam.framework.PersistenceController.getPersistenceContext(PersistenceController.java:20)
          org.jboss.seam.framework.EntityQuery.getEntityManager(EntityQuery.java:159)
          org.jboss.seam.framework.EntityQuery.validate(EntityQuery.java:39)
          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          java.lang.reflect.Method.invoke(Unknown Source)
          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
          org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
          org.jboss.seam.util.Work.workInTransaction(Work.java:47)
          org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
          org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
          org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
          com.kawoolutions.bbstats.semidao.SeasonListQuery_$$_javassist_seam_2.validate(SeasonListQuery_$$_javassist_seam_2.java)
          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          java.lang.reflect.Method.invoke(Unknown Source)
          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
          org.jboss.seam.Component.callComponentMethod(Component.java:2249)
          org.jboss.seam.Component.callCreateMethod(Component.java:2172)
          org.jboss.seam.Component.newInstance(Component.java:2132)
          org.jboss.seam.Component.getInstance(Component.java:2021)
          org.jboss.seam.Component.getInstance(Component.java:1983)
          org.jboss.seam.Component.getInstance(Component.java:1977)
          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
          org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
          org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
          javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
          com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
          org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
          org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
          org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
          com.sun.facelets.el.ELText$ELTextVariable.toString(ELText.java:174)
          com.sun.facelets.el.ELText$ELTextComposite.toString(ELText.java:115)
          com.sun.facelets.compiler.CommentInstruction.write(CommentInstruction.java:38)
          com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
          com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
          javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
          com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
          com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
          com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
          com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
          javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
      



      Here are my persistence.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <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="bbstats" transaction-type="RESOURCE_LOCAL">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <!--jta-data-source>java:comp/env/jdbc/????????????????????</jta-data-source-->
          <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost/bbstats" />
            <property name="hibernate.connection.username" value="lala" />
            <property name="hibernate.connection.password" value="lalalalala" />
      
            <property name="jboss.entity.manager.factory.jndi.name" value="java:comp/env/bbstatsEntityManagerFactory"/>
            
            <property name="hibernate.show_sql" value="true" />
            <!--property name="javax.persistence.validation.mode" value="none" /-->
          </properties>
        </persistence-unit>
      </persistence>



      and my components.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://jboss.com/products/seam/core
                                      http://jboss.com/products/seam/core-2.1.xsd
                                      http://jboss.com/products/seam/components
                                      http://jboss.com/products/seam/components-2.1.xsd">
      
        <!--core:init debug="true" jndi-pattern="@jndiPattern@" / ???? -->
        
        <persistence:managed-persistence-context name="entityManager"
                                                 auto-create="true"
                                                 persistence-unit-jndi-name="java:comp/env/bbstatsEntityManagerFactory" />
        
      </components>



      For Tomcat setups, JNDI names must be prefixed with comp/env AFAIK.


      What do I need to make it work?


      Karsten