5 Replies Latest reply on Mar 7, 2014 11:07 AM by Bharadwaj Narasimha

    On Wildfly8-Final: javax.naming.NotContextException: java:jboss is not a subcontext

    Bharadwaj Narasimha Newbie

      My WAR packages a JAR in its WEB-INF/lib. And the JAR has persistence.xml in its META-INF. My persistence.xml contents are per the instructions in Wildfly JPA wiki -

       

      <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">

              <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

              <non-jta-data-source>java:jboss/datasources/PostgresqlDS</non-jta-data-source>

              <class>in.bharathwrites.models.Test</class>

              <properties>

                  <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

                  <!--<property name="hibernate.show_sql" value="true"/>-->

                  <property name="hibernate.hbm2ddl.auto" value="update"/>

                  <property name="hibernate.format_sql" value="true"/>

              </properties>

      </persistence-unit>

       

      So, as you can see I use Postgres. Have configured the datasource in my standalone-full.xml as shown here -

       

                  <datasources>

                      <datasource jta="true" jndi-name="java:jboss/datasources/PostgresqlDS" pool-name="java:jboss/datasources/PostgresqlDS_Pool" enabled="true" use-java-context="true" use-ccm="true">

                          <connection-url>jdbc:postgresql://localhost:5432/dfadohirbu33sv</connection-url>

                          <driver>postgresql</driver>

                          <security>

                              <user-name>postgres</user-name>

                              <password>mypassword</password>

                          </security>

                      </datasource>

                      <drivers>

                          <driver name="postgresql" module="org.postgres">

                              <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>

                          </driver>

                      </drivers>

                  </datasources>

       

      In the JBoss Management console, under datasources I can see listed my Postgres datasource with JNDI as java:jboss/datasources/PostgresqlDS. When I test the connection its all fine. Despite this, I get this exception and my deployment fails. What could I be doing wrong?

       

      Caused by: javax.persistence.PersistenceException: Unable to build entity manager factory

        at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:81)

        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)

        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)

        at play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:35)

        at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:88)

        at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:88)

        at scala.collection.immutable.List.foreach(List.scala:318)

        at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:88)

        at play.api.Play$$anonfun$start$1.apply(Play.scala:88)

        at play.api.Play$$anonfun$start$1.apply(Play.scala:88)

        at play.utils.Threads$.withContextClassLoader(Threads.scala:18)

        at play.api.Play$.start(Play.scala:87)

        at play.core.server.servlet.WarApplication.<init>(Play2Server.scala:112)

        at play.core.server.servlet.Play2WarServer$.apply(Play2Server.scala:43)

        at play.core.server.servlet.GenericPlay2Servlet.contextInitialized(Play2CommonServlet.scala:45)

        at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)

        at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:187)

        ... 7 more

      Caused by: org.hibernate.engine.jndi.JndiException: Unable to lookup JNDI name [java:jboss/datasources/PostgresqlDS]

        at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:117)

        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115)

        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)

        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)

        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)

        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)

        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)

        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)

        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)

        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)

        at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)

        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)

        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)

        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)

        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)

        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)

        at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:73)

        ... 23 more

      Caused by: javax.naming.NotContextException: java:jboss is not a subcontext

        at tyrex.naming.MemoryContext.internalLookup(Unknown Source)

        at tyrex.naming.MemoryContext.lookup(Unknown Source)

        at javax.naming.InitialContext.lookup(InitialContext.java:415) [rt.jar:1.7.0_21]

        at javax.naming.InitialContext.lookup(InitialContext.java:415) [rt.jar:1.7.0_21]

        at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:114)

        ... 39 more

       

      Message was edited by: Bharadwaj Narasimha Added console.log and server.log