p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Java for Web Applications (http://p2p.wrox.com/forumdisplay.php?f=765)
-   -   Ch 20 JNDI Error (http://p2p.wrox.com/showthread.php?t=92604)

cthielen April 7th, 2014 09:05 PM

Ch 20 JNDI Error
 
I can't for the life of me get the Chapter 20 JNDI stuff to work.

I compile and package the web app via Maven and copy it to Tomache 8 running on Java 8 but get this error:

javax.persistence.PersistenceException: Unable to build entity manager factory
org.hibernate.jpa.HibernatePersistenceProvider.cre ateEntityManagerFactory(HibernatePersistenceProvid er.java:83)
org.hibernate.ejb.HibernatePersistence.createEntit yManagerFactory(HibernatePersistence.java:54)
javax.persistence.Persistence.createEntityManagerF actory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerF actory(Persistence.java:39)
com.wrox.site.EntityServlet.doGet(EntityServlet.ja va:73)
javax.servlet.http.HttpServlet.service(HttpServlet .java:618)
javax.servlet.http.HttpServlet.service(HttpServlet .java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:52)
org.apache.logging.log4j.core.web.Log4jServletFilt er.doFilter(Log4jServletFilter.java:66)

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.Dat asourceConnectionProviderImpl.configure(Datasource ConnectionProviderImpl.java:115)
org.hibernate.boot.registry.internal.StandardServi ceRegistryImpl.configureService(StandardServiceReg istryImpl.java:111)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.initializeService(AbstractServiceRegistry Impl.java:234)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.getService(AbstractServiceRegistryImpl.ja va:206)
org.hibernate.engine.jdbc.internal.JdbcServicesImp l.buildJdbcConnectionAccess(JdbcServicesImpl.java: 260)
org.hibernate.engine.jdbc.internal.JdbcServicesImp l.configure(JdbcServicesImpl.java:94)
org.hibernate.boot.registry.internal.StandardServi ceRegistryImpl.configureService(StandardServiceReg istryImpl.java:111)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.initializeService(AbstractServiceRegistry Impl.java:234)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.getService(AbstractServiceRegistryImpl.ja va:206)
org.hibernate.cfg.Configuration.buildTypeRegistrat ions(Configuration.java:1885)
org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1843)
org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl$4.perform(EntityManagerFactoryBuilde rImpl.java:850)
org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl$4.perform(EntityManagerFactoryBuilde rImpl.java:843)
org.hibernate.boot.registry.classloading.internal. ClassLoaderServiceImpl.withTccl(ClassLoaderService Impl.java:397)
org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.build(EntityManagerFactoryBuilderImp l.java:842)
org.hibernate.jpa.HibernatePersistenceProvider.cre ateEntityManagerFactory(HibernatePersistenceProvid er.java:75)
org.hibernate.ejb.HibernatePersistence.createEntit yManagerFactory(HibernatePersistence.java:54)
javax.persistence.Persistence.createEntityManagerF actory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerF actory(Persistence.java:39)
com.wrox.site.EntityServlet.doGet(EntityServlet.ja va:73)
javax.servlet.http.HttpServlet.service(HttpServlet .java:618)
javax.servlet.http.HttpServlet.service(HttpServlet .java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:52)
org.apache.logging.log4j.core.web.Log4jServletFilt er.doFilter(Log4jServletFilter.java:66)

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(NamingConte xt.java:818)
org.apache.naming.NamingContext.lookup(NamingConte xt.java:152)
javax.naming.InitialContext.lookup(InitialContext. java:421)
org.hibernate.engine.jndi.internal.JndiServiceImpl .locate(JndiServiceImpl.java:114)
org.hibernate.engine.jdbc.connections.internal.Dat asourceConnectionProviderImpl.configure(Datasource ConnectionProviderImpl.java:115)
org.hibernate.boot.registry.internal.StandardServi ceRegistryImpl.configureService(StandardServiceReg istryImpl.java:111)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.initializeService(AbstractServiceRegistry Impl.java:234)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.getService(AbstractServiceRegistryImpl.ja va:206)
org.hibernate.engine.jdbc.internal.JdbcServicesImp l.buildJdbcConnectionAccess(JdbcServicesImpl.java: 260)
org.hibernate.engine.jdbc.internal.JdbcServicesImp l.configure(JdbcServicesImpl.java:94)
org.hibernate.boot.registry.internal.StandardServi ceRegistryImpl.configureService(StandardServiceReg istryImpl.java:111)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.initializeService(AbstractServiceRegistry Impl.java:234)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.getService(AbstractServiceRegistryImpl.ja va:206)
org.hibernate.cfg.Configuration.buildTypeRegistrat ions(Configuration.java:1885)
org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1843)
org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl$4.perform(EntityManagerFactoryBuilde rImpl.java:850)
org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl$4.perform(EntityManagerFactoryBuilde rImpl.java:843)
org.hibernate.boot.registry.classloading.internal. ClassLoaderServiceImpl.withTccl(ClassLoaderService Impl.java:397)
org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.build(EntityManagerFactoryBuilderImp l.java:842)
org.hibernate.jpa.HibernatePersistenceProvider.cre ateEntityManagerFactory(HibernatePersistenceProvid er.java:75)
org.hibernate.ejb.HibernatePersistence.createEntit yManagerFactory(HibernatePersistence.java:54)
javax.persistence.Persistence.createEntityManagerF actory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerF actory(Persistence.java:39)
com.wrox.site.EntityServlet.doGet(EntityServlet.ja va:73)
javax.servlet.http.HttpServlet.service(HttpServlet .java:618)
javax.servlet.http.HttpServlet.service(HttpServlet .java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:52)
org.apache.logging.log4j.core.web.Log4jServletFilt er.doFilter(Log4jServletFilter.java:66)

I've tried putting the valid Resource tag in Tomcat's context.xml as the book suggests as well as the context.xml in the webapp RESOURCE-INF.

When I change the code to merely do a:

<sql:query var="rs" dataSource="jdbc/TestDB">
select id, foo, bar from testdata
</sql:query>

at the top of entities.jsp and disable most of the servlet code, it _works_, indicating that jdbc/TestDB (or jdbc/EntitiesMapping in the case of Ch20) can be found.

Any idea what's going on?

cthielen April 9th, 2014 02:23 PM

I should note the Ch. 21 Spring JPA stuff works fine. It seems to be related to Hibernate's building of Persistence Units via persistence.xml.

Does the author check this forum?

mistre83 April 22nd, 2014 06:47 AM

Hi,
i got exactly the same error. And the chapter 21 code go fine.

I've tried to search on the net but i havent find any solutions.

cthielen April 25th, 2014 11:29 AM

I was informed by the author via Twitter that this is a bug in Hibernate: https://twitter.com/cthielen/status/453972651669614592

beamerblvd June 11th, 2014 11:34 PM

As Chris posted, this is a Hibernate bug which has finally been fixed as of 4.3.6. Hibernate ORM 4.3.6 should be out soon, and once it is, updating this dependency should solve this problem.

Rhywun November 16th, 2014 10:51 PM

Still doesn't work after updating hibernate-entitymanager to version 4.3.7.Final.

BTW, the code download differs from what is written in the book on this line in persistence.xml:

Code:

<non-jta-data-source>java:/comp/env/jdbc/EntityMappings</non-jta-data-source>
The code download has "java:comp" instead of "java:/comp". I don't understand enough to know which is correct - but anyway it doesn't work either way.

pwalessi July 12th, 2015 03:49 PM

Fixed...
 
If anyone is still having this problem, I fixed it by updating the hibernate-entitymanager dependency in the POM file to 4.3.6.Final.

I also had to add a dependency on spring-webmvc.

kross1300 October 22nd, 2016 07:59 AM

Updated Fix for Ch21+
 
Note: This fix is if the issues persist in Ch21+ examples. Ch20 has additional issues that prevent the sample code from working correctly.

Not to revive a dead thread, but this book is still the best resource for self-learning and I had an immense amount of trouble getting the JNDI datasource to work. After trying countless fixed that didn't work, I learned that the nameNotFound exception when working in eclipse was due to the fact that eclipse makes its own copy of the Tomcat configuration. Entering the JNDI datasource definition inside the context file of Tomcat isn't seen when running from within eclipse. To make the datasource visible all you need to do is open the context.xml from WITHIN eclipse and paste in the datasource as seen here:

http://www.codejava.net/servers/tomc...ling-in-tomcat

After literally hours upon hours of troubleshooting, this 5 second fix may work for you too!


All times are GMT -4. The time now is 05:59 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.