Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 7th, 2014, 09:05 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #2 (permalink)  
Old April 9th, 2014, 02:23 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #3 (permalink)  
Old April 22nd, 2014, 06:47 AM
Authorized User
Points: 52, Level: 1
Points: 52, Level: 1 Points: 52, Level: 1 Points: 52, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #4 (permalink)  
Old April 25th, 2014, 11:29 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #5 (permalink)  
Old June 11th, 2014, 11:34 PM
Wrox Author
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #6 (permalink)  
Old November 16th, 2014, 10:51 PM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: , , .
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.
Reply With Quote
  #7 (permalink)  
Old July 12th, 2015, 03:49 PM
Wrox Author
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #8 (permalink)  
Old October 22nd, 2016, 07:59 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:23 AM.


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