Hi Violeta

this property doesnt makes the scope of the resource prototype so we should
still have a single instance. That said the JPA usage is a bit harder:

- you need to explicitely define the jta AND non jta datasource (otherwise
we create the nonJta on the fly and it fails cause it is not lazy)
- I skipped on master (7.x) lazy resource merge in tomcat jndi tree to
avoid the first exception to be seen and tomcat to try to process them at
startup. This then makes the remove() working as expected - the remove is
intended to avoid to consider this virtual property as a real one in the
"object factory".





Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-12-01 20:31 GMT+01:00 Violeta Georgieva <[email protected]>:

> Hello,
>
> I'm testing with TomEE 1.7.3
> I'm describing the resource using the following system properties:
>
> mypostgres=new://Resource?type=DataSource
> mypostgres.JdbcDriver=org.postgresql.Driver
> mypostgres.JdbcUrl=url
> mypostgres.UserName=user
> mypostgres.Password=password
> mypostgres.JtaManaged=true
> mypostgres.Lazy=true
> mypostgres.UseAppClassLoader=true
> mypostgres.InitializeAfterDeployment=false
>
> I supply the driver with my web application (WEB-INF/lib).
>
> Regardless that I specify that I want initialization of the resource to
> happen on the first lookup with the application class loader, my
> application
> fails with the exceptions below.
>
> When I debugged I saw that
> The first time - OpenEJBNamingContextListener.bindResource - case 1) below
> the loader is StandardClassLoader and UseAppClassLoader=true.
> At this point, UseAppClassLoader property is removed. The lookup is not
> working because of the loader.
>
> org.apache.openejb.assembler.classic.Assembler.newLazyResource(ResourceInfo)
> row 2536
>
> The second time - PersistenceBuilder.createEntityManagerFactory - case 2)
> below
> the loader is the webapp classloader but UseAppClassLoader=false because it
> was removed on the previous step and the lookup is not working anymore.
>
> From my point of view the property should not be removed in order to enable
> this scenario.
>
>
> Thanks,
> Violeta
>
>
> 1)
> SEVERE: Unable to lookup Global Tomcat resource mypostgres
> javax.naming.NamingException: Unable to resolve class org.postgresql.Driver
>         at
>
> org.apache.openejb.core.ivm.naming.LazyObjectReference.getObject(LazyObjectReference.java:39)
>         at
> org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:175)
>         at
> org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:123)
>         at
>
> org.apache.tomee.common.AbstractObjectFactory.lookup(AbstractObjectFactory.java:102)
>         at
>
> org.apache.tomee.common.AbstractObjectFactory.getObjectInstance(AbstractObjectFactory.java:51)
>         at
>
> org.apache.tomee.common.ResourceFactory.getObjectInstance(ResourceFactory.java:49)
>         at
>
> org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:141)
>         at
> javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
>         at org.apache.naming.NamingContext.lookup(NamingContext.java:842)
>         at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
>         at
>
> org.apache.tomee.catalina.OpenEJBNamingContextListener.bindResource(OpenEJBNamingContextListener.java:266)
>         at
>
> org.apache.tomee.catalina.OpenEJBNamingContextListener.addResource(OpenEJBNamingContextListener.java:256)
>         at
>
> org.apache.tomee.catalina.OpenEJBNamingContextListener.processInitialNamingResources(OpenEJBNamingContextListener.java:223)
>         at
>
> org.apache.tomee.catalina.OpenEJBNamingContextListener.start(OpenEJBNamingContextListener.java:92)
>         at
>
> org.apache.tomee.catalina.OpenEJBNamingContextListener.lifecycleEvent(OpenEJBNamingContextListener.java:74)
>         at
>
> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>         at
>
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
>         at
>
> org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
>         at
> org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:347)
>         at
>
> org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
>         at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>         at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>         at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:606)
>         at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
>         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
>
> 2)
> org.apache.openejb.OpenEJBException: Could not lookup <jta-data-source>
> 'openejb/Resource/mypostgres' for unit 'persistence-with-ejb': Unable to
> resolve class org.postgresql.Driver: Could not lookup <jta-data-source>
> 'openejb/Resource/mypostgres' for unit 'persistence-with-ejb': Unable to
> resolve class org.postgresql.Driver
>         at
>
> org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:843)
>         at
>
> org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:677)
>         at
>
> org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1261)
>         at
>
> org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1100)
>         at
>
> org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
>         at
>
> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>         at
>
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
>         at
>
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5419)
>         at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>         at
>
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
>         at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
>         at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
>         at
> org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095)
>         at
> org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930)
>         at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:262)
>         at
>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>         at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>         at java.lang.Thread.run(Thread.java:745)
> Caused by: org.apache.openejb.OpenEJBException:
> org.apache.openejb.OpenEJBException: Could not lookup <jta-data-source>
> 'openejb/Resource/mypostgres' for unit 'persistence-with-ejb': Unable to
> resolve class org.postgresql.Driver: Could not lookup <jta-data-source>
> 'openejb/Resource/mypostgres' for unit 'persistence-with-ejb': Unable to
> resolve class org.postgresql.Driver
>         at
>
> org.apache.openejb.assembler.classic.Assembler.loadPersistenceUnits(Assembler.java:988)
>         at
>
> org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:741)
>         ... 18 more
> Caused by: org.apache.openejb.OpenEJBException: Could not lookup
> <jta-data-source> 'openejb/Resource/mypostgres' for unit
> 'persistence-with-ejb': Unable to resolve class org.postgresql.Driver
>         at
>
> org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityManagerFactory(PersistenceBuilder.java:93)
>         at
>
> org.apache.openejb.assembler.classic.Assembler.loadPersistenceUnits(Assembler.java:982)
>         ... 19 more
> Caused by: javax.naming.NamingException: Unable to resolve class
> org.postgresql.Driver
>         at
>
> org.apache.openejb.core.ivm.naming.LazyObjectReference.getObject(LazyObjectReference.java:39)
>         at
> org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:175)
>         at
>
> org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityManagerFactory(PersistenceBuilder.java:87)
>         ... 20 more
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Resource-and-UseAppClassLoader-question-tp4677073.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Reply via email to