You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christian <cm...@famiru.de> on 2014/04/13 13:10:17 UTC

JNDI initialization since Tomcat 8.0.1

Hi,

I'm experimenting with java 8, spring data JPA, hibernate and tomcat 8.
Spring Data JPA initializes hibernate on deployment.

On tomcat 8.0.0-RC10 everything is fine. Using Tomcat 8.0.1 or newer, an
exception is thrown when hibernate tries to fetch the datasource from JNDI:

javax.naming.NameNotFoundException: Name [java:comp/env/jdbc/myDB] is
not bound in this Context. Unable to find [java:comp].
	at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at javax.naming.InitialContext.lookup(InitialContext.java:421)
	at
org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:114)
	...

The part of the thread dump concerning tomcat:
...
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4737)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5159)
	- locked <0x1aea> (a org.apache.catalina.core.StandardContext)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1646)
...


When I disable hibernate and use the following snippet in a controller,
the DataSource is returned correctly:
Context initCtx = new InitialContext();
DataSource dataSource = (DataSource)
initCtx.lookup("java:comp/env/jdbc/myDB");

I have configured the datasource in META-INF/context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/">
    <Resource name="jdbc/myDB"
              auth="Container"
              type="javax.sql.DataSource"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/test"/>
</Context>

And referenced it in web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <resource-ref>
        <res-ref-name>jdbc/myDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

Of course the mysql driver is copied into $CATALINA_BASE/lib.

Has the JNDI initialization changed between tomcat 8.0.0-RC10 and 8.0.1?

Regards,

Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNDI initialization since Tomcat 8.0.1

Posted by Christian <cm...@famiru.de>.
There is already a hibernate issue on this bug 
(https://hibernate.atlassian.net/browse/HHH-8818).

Regards,
Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNDI initialization since Tomcat 8.0.1

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

David,

On 4/16/14, 10:44 AM, David Landis wrote:
> On Sun, Apr 13, 2014 at 4:02 PM, Konstantin Kolinko 
> <kn...@gmail.com>wrote:
>> 
>> 
>> By the way, there exists an Apache project implementing the JPA 
>> specification, http://openjpa.apache.org/
> 
> 
> It does not really work with Tomcat though does it? See this
> issue: https://issues.apache.org/jira/browse/OPENJPA-1590
> 
> or others. Also the build-time enhancement is a mess people
> shouldn't have to deal with. I was disappointed by this myself, not
> to mention that nobody seems to update the openjpa website anymore
> nor do they support jpa 2.1. Stalled project.

You'd better not tell the TomEE project that OpenJPA doesn't work with
Tomcat. They might have to stop claiming they are doing it.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJTTwMZAAoJEBzwKT+lPKRYMmQQAJLG2tVwJQ5lvHF94cdt5mh/
z2x+LaQ/SlOlF4stw8BEpxo5z/rbKDIigUfvaJST5d/Z7llPdWRfMo5C1lJjJvcg
LvFHj4ivyrwBYLxhHRjj2/0HpR+HElSDBC0LmfqbJAeViR8LgtKPYcVrxv0CyWyH
unO7+6RR8sx+MSxlNruGdkZQzryDIrrsohswZCzTY5LlM7smtcRKBZqcZKa2OoVz
EFwp3AUlWw2VA8Lu9wEnkph9TFlp8zRy9O2I8MUCq6caE7tEhNBIe1VatO6pYLpI
VlPNVchTbgz6LisfSTLPE3nLE69dHi5ejG6Je6tqsXX0I2kcgvAVNEIHXlhGUolK
ea/RV/6mipIbhXZDudDsKdNW8HFW+x916oCxJvPwaQcx2v2wuHiuEizCarWg+ZVR
aCOTP3klP+BocfaHVrpe4JvfTb3uMXD4vgbD3Hbs3k/PtI9bmJ1Bj86/JDMqI+XY
8Kz+P+ItPkEPldr9/jSDCot4JlDhOWLoaCAsuQF3UN5+ZLbtXFjYkWt1y5ugqUiM
bfoBJubrHapIYd5c66jo1jf9dylI8+BlvwU5mXGSPSoqnrpVj9nn956NlJ7E5a0H
MzBULsMy1tbFF+NBPKFzpG9OicHbMKvL3EKQLj+d0F+DBmwwcXYsjYJJ+j87LdGL
1PM2wDFrorUnFJs2F+Xy
=vTHo
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNDI initialization since Tomcat 8.0.1

Posted by David Landis <dl...@gmail.com>.
On Sun, Apr 13, 2014 at 4:02 PM, Konstantin Kolinko
<kn...@gmail.com>wrote:
>
>
> By the way, there exists an Apache project implementing the JPA
> specification,
> http://openjpa.apache.org/


It does not really work with Tomcat though does it? See this issue:
https://issues.apache.org/jira/browse/OPENJPA-1590

or others. Also the build-time enhancement is a mess people shouldn't have
to deal with. I was disappointed by this myself, not to mention that nobody
seems to update the openjpa website anymore nor do they support jpa 2.1.
Stalled project.

Re: JNDI initialization since Tomcat 8.0.1

Posted by Christian <cm...@famiru.de>.
On 13.04.2014 22:02, Konstantin Kolinko wrote:
> I do not know, what version of hibernate you are using, but if I look
> at 4.3.x sources [1], the following method mentioned in your
> stacktrace changes TCCL and thus breaks JNDI:
> 
> org.hibernate.boot.registry.
> classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)

Great pointer! You're right, I use hibernate 4.3.
I followed your suggestion an asked at hibernate forums.

https://forum.hibernate.org/viewtopic.php?f=1&t=1032307

Regards,
Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNDI initialization since Tomcat 8.0.1

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-04-13 19:32 GMT+04:00 Christian <cm...@famiru.de>:
>> Is hibernate initialized via a <listener> in web.xml,  or where?
>
> I don't know exactly how it is initialized. I use spring annotation configuration with a
> javax.servlet.ServletContainerInitializer but I don't know, if hibernate gets loaded immediately.
> Looking at the call stack, it seems that it gets initialized by a "ContextLoaderListener" in an event called
> "contextInitialized" that gets passed a javax.servlet.ServletContextEvent.
> So I would say yes, it gets initialized by a listener.
>
>
>> "path" attribute cannot be used in META-INF/context.xml file.
>
> Thanks for the hint.
>
>
>> The driver jar should be in one place, not both.
>
> They are just in $CATALINA_BASE/lib and not bundled with the webapp.
>
>
>>  a) classloading for drivers was changed at some point, to allow them
>> in WEB-INF/lib
>
> This might be the cause - if resources get registered later to allow loading the driver before.
>
>
>>  b) different versions of Tomcat 8 use different versions of Apache
>> Commons DBCP 2 pool
>
> Explicitly using
> factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
> in context.xml to use tomcat dbcp doesn't change the behavior.
>
>
>> The visible part of JNDI depends on
>> Thread.currentThread().getContextClassLoader() (aka TCCL). Any reason
>> why TCCL may be wrong? (You aren't providing the full stacktrace)
>
> The full stacktrace gets truncated by my IDE, because it is very long (the exception causes 3 other exceptions that get
> printed with complete stacktrace).
> I copied the thread dump at the statement directly after the exception got thrown:
>
> "RMI TCP Connection(4)-127.0.0.1@1847" daemon prio=5 tid=0x42 nid=NA runnable
>   java.lang.Thread.State: RUNNABLE
>           at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:117)
>           at
> org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115)
>           at
> org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
>           at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
>           at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
>           at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
>           at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
>           at
> org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
>           at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
>           at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
>           at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
>           at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
>           at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
>           at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
>           at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)
>           at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
>           at
> org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
>           at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
>           at
> org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:290)
>           at
> org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
>           at config.PersistenceConfig.entityManagerFactory(PersistenceConfig.java:35)
>           at config.PersistenceConfig$$EnhancerByCGLIB$$57464d4c.CGLIB$entityManagerFactory$0(<generated>:-1)
>           at config.PersistenceConfig$$EnhancerByCGLIB$$57464d4c$$FastClassByCGLIB$$58f7e9b4.invoke(<generated>:-1)
>           at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
>           at
> org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:326)
>           at config.PersistenceConfig$$EnhancerByCGLIB$$57464d4c.entityManagerFactory(<generated>:-1)
>           at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
>           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>           at java.lang.reflect.Method.invoke(Method.java:483)
>           at
> org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
>           at
> org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
>           at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
>           at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
>           at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
>           at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
>           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
>           at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
>           - locked <0xec7> (a java.util.concurrent.ConcurrentHashMap)
>           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
>           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
>           at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
>           at
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
>           at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
>           - locked <0xec8> (a java.lang.Object)
>           at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
>           at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
>           at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
>           at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4737)
>           at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5159)
>           - locked <0xe8d> (a org.apache.catalina.core.StandardContext)
>           at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>           at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
>           at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
>           at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
>           at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1646)
>           at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
>           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>           at java.lang.reflect.Method.invoke(Method.java:483)
>           at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
>           at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
>           at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
>           at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463)
>           at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413)
>           at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
>           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>           at java.lang.reflect.Method.invoke(Method.java:483)
>           at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
>           at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
>           at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
>           at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
>           at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
>           at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
>           at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399)
>           at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:828)
>           at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
>           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>           at java.lang.reflect.Method.invoke(Method.java:483)
>           at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
>           at sun.rmi.transport.Transport$1.run(Transport.java:178)
>           at sun.rmi.transport.Transport$1.run(Transport.java:175)
>           at java.security.AccessController.doPrivileged(AccessController.java:-1)
>           at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
>           at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557)
>           at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812)
>           at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671)
>           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>           at java.lang.Thread.run(Thread.java:744)
>
>
>
>
>> Maybe you can try debugging, with a breakpoint in org.apache.naming.* classes?
>
> I don't know where I should look. I started looking at the failing lookup() statement.
> org.apache.naming.java.javaURLContextFactory#getObjectInstance() calls ContextBindings.isThreadBound() and
> ContextBindings.isClassLoaderBound() - both return false.
> In tomcat 8.0.0-RC10 ContextBindings.isThreadBound() returns true and the name resolution succeeds.
>
> Maybe this directs to the cause of the problem.
>

I do not know, what version of hibernate you are using, but if I look
at 4.3.x sources [1], the following method mentioned in your
stacktrace changes TCCL and thus breaks JNDI:

org.hibernate.boot.registry.
classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)

[1] https://github.com/hibernate/hibernate-orm/blob/4.3/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java#l384


I suggest you to ask at hibernate forums.

By the way, there exists an Apache project implementing the JPA specification,
http://openjpa.apache.org/

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNDI initialization since Tomcat 8.0.1

Posted by Christian <cm...@famiru.de>.
> Is hibernate initialized via a <listener> in web.xml,  or where?

I don't know exactly how it is initialized. I use spring annotation configuration with a
javax.servlet.ServletContainerInitializer but I don't know, if hibernate gets loaded immediately.
Looking at the call stack, it seems that it gets initialized by a "ContextLoaderListener" in an event called
"contextInitialized" that gets passed a javax.servlet.ServletContextEvent.
So I would say yes, it gets initialized by a listener.


> "path" attribute cannot be used in META-INF/context.xml file.

Thanks for the hint.


> The driver jar should be in one place, not both.

They are just in $CATALINA_BASE/lib and not bundled with the webapp.


>  a) classloading for drivers was changed at some point, to allow them
> in WEB-INF/lib

This might be the cause - if resources get registered later to allow loading the driver before.


>  b) different versions of Tomcat 8 use different versions of Apache
> Commons DBCP 2 pool

Explicitly using
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
in context.xml to use tomcat dbcp doesn't change the behavior.


> The visible part of JNDI depends on
> Thread.currentThread().getContextClassLoader() (aka TCCL). Any reason
> why TCCL may be wrong? (You aren't providing the full stacktrace)

The full stacktrace gets truncated by my IDE, because it is very long (the exception causes 3 other exceptions that get
printed with complete stacktrace).
I copied the thread dump at the statement directly after the exception got thrown:

"RMI TCP Connection(4)-127.0.0.1@1847" daemon prio=5 tid=0x42 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:117)
	  at
org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115)
	  at
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
	  at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
	  at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
	  at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
	  at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
	  at
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
	  at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
	  at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
	  at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
	  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
	  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
	  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
	  at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)
	  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
	  at
org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
	  at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
	  at
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:290)
	  at
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
	  at config.PersistenceConfig.entityManagerFactory(PersistenceConfig.java:35)
	  at config.PersistenceConfig$$EnhancerByCGLIB$$57464d4c.CGLIB$entityManagerFactory$0(<generated>:-1)
	  at config.PersistenceConfig$$EnhancerByCGLIB$$57464d4c$$FastClassByCGLIB$$58f7e9b4.invoke(<generated>:-1)
	  at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	  at
org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:326)
	  at config.PersistenceConfig$$EnhancerByCGLIB$$57464d4c.entityManagerFactory(<generated>:-1)
	  at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
	  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	  at java.lang.reflect.Method.invoke(Method.java:483)
	  at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
	  at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
	  at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
	  at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
	  at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
	  at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
	  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
	  at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	  - locked <0xec7> (a java.util.concurrent.ConcurrentHashMap)
	  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
	  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
	  at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
	  at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
	  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
	  - locked <0xec8> (a java.lang.Object)
	  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
	  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4737)
	  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5159)
	  - locked <0xe8d> (a org.apache.catalina.core.StandardContext)
	  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	  at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
	  at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
	  at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
	  at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1646)
	  at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
	  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	  at java.lang.reflect.Method.invoke(Method.java:483)
	  at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
	  at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	  at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	  at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463)
	  at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413)
	  at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
	  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	  at java.lang.reflect.Method.invoke(Method.java:483)
	  at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
	  at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	  at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	  at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
	  at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
	  at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
	  at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399)
	  at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:828)
	  at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
	  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	  at java.lang.reflect.Method.invoke(Method.java:483)
	  at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
	  at sun.rmi.transport.Transport$1.run(Transport.java:178)
	  at sun.rmi.transport.Transport$1.run(Transport.java:175)
	  at java.security.AccessController.doPrivileged(AccessController.java:-1)
	  at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
	  at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557)
	  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812)
	  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671)
	  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	  at java.lang.Thread.run(Thread.java:744)




> Maybe you can try debugging, with a breakpoint in org.apache.naming.* classes?

I don't know where I should look. I started looking at the failing lookup() statement.
org.apache.naming.java.javaURLContextFactory#getObjectInstance() calls ContextBindings.isThreadBound() and
ContextBindings.isClassLoaderBound() - both return false.
In tomcat 8.0.0-RC10 ContextBindings.isThreadBound() returns true and the name resolution succeeds.

Maybe this directs to the cause of the problem.

Regards,
Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNDI initialization since Tomcat 8.0.1

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-04-13 15:10 GMT+04:00 Christian <cm...@famiru.de>:
> Hi,
>
> I'm experimenting with java 8, spring data JPA, hibernate and tomcat 8.
> Spring Data JPA initializes hibernate on deployment.
>
> On tomcat 8.0.0-RC10 everything is fine. Using Tomcat 8.0.1 or newer, an
> exception is thrown when hibernate tries to fetch the datasource from JNDI:
>
> (....)
> ...
> at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4737)
> at
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5159)
>         - locked <0x1aea> (a org.apache.catalina.core.StandardContext)
> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
> at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
> at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
> at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1646)
> ...
>
>
> When I disable hibernate and use the following snippet in a controller,
> the DataSource is returned correctly:
> Context initCtx = new InitialContext();
> DataSource dataSource = (DataSource)
> initCtx.lookup("java:comp/env/jdbc/myDB");
>
> I have configured the datasource in META-INF/context.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <Context path="/">
>     <Resource name="jdbc/myDB"
>               auth="Container"
>               type="javax.sql.DataSource"
>               driverClassName="com.mysql.jdbc.Driver"
>               url="jdbc:mysql://localhost:3306/test"/>
> </Context>
>
> And referenced it in web.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xmlns="http://xmlns.jcp.org/xml/ns/javaee"
>          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
>          http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
>          version="3.1">
>     <resource-ref>
>         <res-ref-name>jdbc/myDB</res-ref-name>
>         <res-type>javax.sql.DataSource</res-type>
>         <res-auth>Container</res-auth>
>     </resource-ref>
> </web-app>
>
> Of course the mysql driver is copied into $CATALINA_BASE/lib.
>
> Has the JNDI initialization changed between tomcat 8.0.0-RC10 and 8.0.1?
>

Is hibernate initialized via a <listener> in web.xml,  or where?

"path" attribute cannot be used in META-INF/context.xml file.

The driver jar should be in one place, not both.

IIRC,
 a) classloading for drivers was changed at some point, to allow them
in WEB-INF/lib
 b) different versions of Tomcat 8 use different versions of Apache
Commons DBCP 2 pool

The visible part of JNDI depends on
Thread.currentThread().getContextClassLoader() (aka TCCL). Any reason
why TCCL may be wrong? (You aren't providing the full stacktrace)

Maybe you can try debugging, with a breakpoint in org.apache.naming.* classes?
http://wiki.apache.org/tomcat/FAQ/Developing#Debugging

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org