View Single Post
  #1 (permalink)  
Old April 7th, 2014, 09:05 PM
cthielen cthielen is offline
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