We're updating the issue view to help you get more done. 

Hibernate 4.3.0.Final can no longer find JNDI DataSource that <=4.2.x and 4.3.0.Beta4 could find

Description

I have attached a simple, one-Servlet project that duplicates this issue. You can also see the issue reported in this Stack Overflow question (I didn't post that) and this forum post (posted by the same person it appears).

The attached project worked fine with Hibernate 4.2.x and through Hibernate 4.3.0.Beta4. I have not tested with 4.3.0.Beta5-4.3.0.CR1, but 4.3.0.CR2 and 4.3.0.Final result in the following error on Tomcat 7 and 8:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 javax.persistence.PersistenceException: Unable to build entity manager factory org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:81) org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) com.wrox.site.EntityServlet.init(EntityServlet.java:49) javax.servlet.GenericServlet.init(GenericServlet.java:160) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:76) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:646) org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1576) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1534) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:744) root cause org.hibernate.engine.jndi.JndiException: Unable to lookup JNDI name [java:comp/env/jdbc/EntityMappings] org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:117) org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115) org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89) org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206) org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260) org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94) org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89) org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206) org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885) org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843) org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:73) org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) com.wrox.site.EntityServlet.init(EntityServlet.java:49) javax.servlet.GenericServlet.init(GenericServlet.java:160) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:76) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:646) org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1576) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1534) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:744) root cause javax.naming.NameNotFoundException: Name [java:comp/env/jdbc/EntityMappings] is not bound in this Context. Unable to find [java:comp]. org.apache.naming.NamingContext.lookup(NamingContext.java:820) org.apache.naming.NamingContext.lookup(NamingContext.java:153) javax.naming.InitialContext.lookup(InitialContext.java:421) org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:114) org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115) org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89) org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206) org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260) org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94) org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89) org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206) org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885) org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843) org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:73) org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) com.wrox.site.EntityServlet.init(EntityServlet.java:49) javax.servlet.GenericServlet.init(GenericServlet.java:160) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:76) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:646) org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1576) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1534) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:744)

It would appear that, starting somewhere in 4.3.0.Beta5, 4.3.0.CR1, or 4.3.0.CR2, Hibernate stopped being able to resolve JNDI DataSource resources in Tomcat. This makes Hibernate 4.3.0.Final completely unusable, meaning this is a blocking issue. Until this is fixed, I will have to downgrade to 4.3.0.Beta4.

The reporter of the Stack Overflow question and forum post believes he has found the likely culprit: a change in the JndiServiceImpl#locate method.

Environment

None

Status

Assignee

Brett Meyer

Reporter

Nick Williams

Requires Release Note

Affirmative

Components

Fix versions

Affects versions

4.3.0.CR2
4.3.0.Final

Priority

Blocker