Wrox Programmer Forums
|
BOOK: Professional Java for Web Applications
This is the forum to discuss the Wrox book Professional Java for Web Applications by Nicholas S. Williams; ISBN: 978-1-118-65646-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Java for Web Applications section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 7th, 2014, 09:05 PM
Registered User
 
Join Date: Apr 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old April 9th, 2014, 02:23 PM
Registered User
 
Join Date: Apr 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
 
Old April 22nd, 2014, 06:47 AM
Authorized User
 
Join Date: Apr 2014
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old April 25th, 2014, 11:29 AM
Registered User
 
Join Date: Apr 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was informed by the author via Twitter that this is a bug in Hibernate: https://twitter.com/cthielen/status/453972651669614592
 
Old June 11th, 2014, 11:34 PM
Wrox Author
 
Join Date: Jun 2014
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
__________________
-- Nick Williams
 
Old November 16th, 2014, 10:51 PM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old July 12th, 2015, 03:49 PM
Wrox Author
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old October 22nd, 2016, 07:59 AM
Registered User
 
Join Date: Oct 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 20 - best practices Jgribb BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 November 2nd, 2011 04:05 AM
CH 20 Database Controls cpfuller BOOK: Visual Basic 2010 Programmer's Reference 3 July 3rd, 2011 10:50 AM
Not binding factory to JNDI, no JNDI name configur 4java EJB 0 August 13th, 2007 11:20 AM
SQL Express & Ch 20 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 1 August 2nd, 2007 05:16 PM
JNDI Error ofer_mizrahi J2EE 0 November 27th, 2003 08:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.