You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by David Blevins <da...@visi.com> on 2009/12/08 23:52:06 UTC

Re: When using EclipseLink javaagent, EntityManager is unable to open a connection to DB

This is a strange error indeed.  I would have expected to see any  
agent related issues much sooner (i.e. while the vm is booting) rather  
than at EJB method invoke time.  I assume line 85 of your test case  
corresponds to "svc.createObject(key);"

The strange part is that EclipseLink seems to be trying to create its  
own DataSource instances which is a no-no.  We need to figure out how  
to get it to stop doing that and to use the ones we provide instead.   
Can you post your startup log output?  It should show which  
DataSources have been linked to the persistence-unit.

One side thing I notice is that you've named your InitialContext  
configured DataSource "TestPU" which is the same name as your  
persistence unit.  The effect of that is that all the properties you  
set on "TestPU" will be applied to your persistence unit as well.   
Normally this is fine as the PersistenProvider will usually just  
ignore properties it doesn't support, but I wonder if one or more of  
these extra properties might be what causes EclipseLink to try and  
create DataSources on its own.  Try renaming the InitialContext  
configured DataSource to something else like "TestDS".

One last thing you could try is to remove the eclipse link agent and  
use our agent jar instead, then explicitly list the classes that need  
to be dynamically enhanced via the <class> tag in your persistence  
unit declaration.  What we'll do is attempt to get your persistence  
provider to enhance those classes before JUnit loads them and they can  
not longer be enhanced -- unless of course you're on Java 6 and then  
you don't need a JavaAgent anymore as classes can be redifined by the  
Persistence Provider via hooks that are available post-startup.  Not  
sure if EclipseLink supports that though.  I know OpenJPA does and the  
two are pretty competitive feature wise.

Hope some part of this is helpful.

-David


On Nov 25, 2009, at 5:26 PM, babstr wrote:

>
> I have been attempting to use OpenEJB for unit testing a JavaEE  
> application
> which uses EclipseLink as its Persistence provider.  In order to  
> verify that
> everything works I created a simple JavaEE application that consists  
> of one
> EJB with local interface methods and two JPA entities.  With this  
> setup, I
> was able to get a unit test which invokes an EJB local method which  
> in turn
> creates and removes instances of the JPA entities.
>
> Now, a problem occurs if I create a relation between the two JPA  
> entities
> that is marked as FetchType.LAZY.  These relation types requires  
> weaving of
> the bytecode.  So, I went ahead and added the eclipselink.jar to the
> command-line for the unit tests using the javaagent parameter.   
> Once, I do
> this, the unit test no longer runs, but instead I get the following  
> error
> message:
>
>
> The bean encountered a non-application exception; nested exception is:
>        javax.persistence.PersistenceException: Exception  
> [EclipseLink-4021]
> (Eclipse Persistence Services - 1.1.0.r3634):
> org.eclipse.persistence.exceptions.DatabaseException
> Exception Description: Unable to acquire a connection from driver  
> [null],
> user [null] and URL [null].  Verify that you have set the expected  
> driver
> class and URL.  Check your login, persistence.xml or sessions.xml  
> resource.
> The jdbc.driver property should be set to a class that is compatible  
> with
> your database platform
> javax.ejb.EJBException: The bean encountered a non-application  
> exception;
> nested exception is:
>        javax.persistence.PersistenceException: Exception  
> [EclipseLink-4021]
> (Eclipse Persistence Services - 1.1.0.r3634):
> org.eclipse.persistence.exceptions.DatabaseException
> Exception Description: Unable to acquire a connection from driver  
> [null],
> user [null] and URL [null].  Verify that you have set the expected  
> driver
> class and URL.  Check your login, persistence.xml or sessions.xml  
> resource.
> The jdbc.driver property should be set to a class that is compatible  
> with
> your database platform
>        at
> org 
> .apache 
> .openejb 
> .core 
> .ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java: 
> 358)
>        at
> org 
> .apache 
> .openejb 
> .core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:286)
>        at $Proxy34.createObject(Unknown Source)
>        at HellowWorldTest.testPersistence(HellowWorldTest.java:85)
> Caused by: javax.persistence.PersistenceException: Exception
> [EclipseLink-4021] (Eclipse Persistence Services - 1.1.0.r3634):
> org.eclipse.persistence.exceptions.DatabaseException
> Exception Description: Unable to acquire a connection from driver  
> [null],
> user [null] and URL [null].  Verify that you have set the expected  
> driver
> class and URL.  Check your login, persistence.xml or sessions.xml  
> resource.
> The jdbc.driver property should be set to a class that is compatible  
> with
> your database platform
>        at
> org 
> .eclipse 
> .persistence 
> .internal 
> .jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:272)
>        at
> org 
> .eclipse 
> .persistence 
> .internal 
> .jpa 
> .EntityManagerFactoryImpl 
> .getServerSession(EntityManagerFactoryImpl.java:111)
>        at
> org 
> .eclipse 
> .persistence 
> .internal 
> .jpa 
> .EntityManagerFactoryImpl 
> .createEntityManagerImpl(EntityManagerFactoryImpl.java:163)
>        at
> org 
> .eclipse 
> .persistence 
> .internal 
> .jpa 
> .EntityManagerFactoryImpl 
> .createEntityManager(EntityManagerFactoryImpl.java:158)
>        at
> org 
> .apache 
> .openejb 
> .persistence 
> .JtaEntityManagerRegistry 
> .getEntityManager(JtaEntityManagerRegistry.java:105)
>        at
> org 
> .apache 
> .openejb 
> .persistence.JtaEntityManager.getEntityManager(JtaEntityManager.java: 
> 61)
>        at
> org 
> .apache 
> .openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java: 
> 97)
>        at or.babic.HellowWorldBean.createObject(HellowWorldBean.java: 
> 47)
>        at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext 
> $Invocation.invoke(ReflectionInvocationContext.java:158)
>        at
> org 
> .apache 
> .openejb 
> .core 
> .interceptor 
> .ReflectionInvocationContext 
> .proceed(ReflectionInvocationContext.java:141)
>        at
> org 
> .apache 
> .openejb 
> .core.interceptor.InterceptorStack.invoke(InterceptorStack.java:122)
>        at
> org 
> .apache 
> .openejb 
> .core.stateless.StatelessContainer._invoke(StatelessContainer.java: 
> 221)
>        at
> org 
> .apache 
> .openejb 
> .core.stateless.StatelessContainer.invoke(StatelessContainer.java:174)
>        at
> org 
> .apache 
> .openejb 
> .core 
> .ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java: 
> 217)
>        at
> org 
> .apache 
> .openejb 
> .core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
>        at
> org 
> .apache 
> .openejb 
> .core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:281)
> Caused by: Exception [EclipseLink-4021] (Eclipse Persistence  
> Services -
> 1.1.0.r3634): org.eclipse.persistence.exceptions.DatabaseException
> Exception Description: Unable to acquire a connection from driver  
> [null],
> user [null] and URL [null].  Verify that you have set the expected  
> driver
> class and URL.  Check your login, persistence.xml or sessions.xml  
> resource.
> The jdbc.driver property should be set to a class that is compatible  
> with
> your database platform
>        at
> org 
> .eclipse 
> .persistence 
> .exceptions 
> .DatabaseException 
> .unableToAcquireConnectionFromDriverException(DatabaseException.java: 
> 365)
>        at
> org 
> .eclipse 
> .persistence.sessions.DefaultConnector.connect(DefaultConnector.java: 
> 90)
>        at
> org 
> .eclipse 
> .persistence 
> .sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java: 
> 162)
>        at
> org 
> .eclipse 
> .persistence 
> .internal 
> .sessions 
> .DatabaseSessionImpl 
> .loginAndDetectDatasource(DatabaseSessionImpl.java:583)
>        at
> org 
> .eclipse 
> .persistence 
> .internal 
> .jpa 
> .EntityManagerFactoryProvider 
> .login(EntityManagerFactoryProvider.java:227)
>
>
> I have tried various configurations with the InitialContext, but so  
> far have
> been unsuccessful.  Any insight into this problem would be greatly
> appreciated.
>
> Here is a breakdown of the sample code:
> OpenEJB v3.1.2
> EclipseLink v1.1
> DB Oracle 10g
>
>
> persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence 
> "
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>    <persistence-unit name="TestPU">
>        <provider>org.eclipse.persistence.jpa.PersistenceProvider</ 
> provider>
>        <jta-data-source>jdbc/MyDatasource</jta-data-source>
>        <exclude-unlisted-classes>false</exclude-unlisted-classes>
>        <properties>
>            <property name="eclipselink.logging.level" value="FINEST"/>
>        </properties>
>    </persistence-unit>
> </persistence>
>
> public class HellowWorldTest {
>    @Test
>    public void testPersistence() throws Exception {
>        Properties props = new Properties();
>        props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>
> "org.apache.openejb.client.LocalInitialContextFactory");
>
>        props.put("TestPU", "new://Resource?type=DataSource");
>        props.put("TestPU.JtaManaged", "true");
>        props.put("TestPU.JdbcDriver", "oracle.jdbc.OracleDriver");
>        props.put("TestPU.JdbcUrl", "jdbc:oracle:thin:@localhost: 
> 1521:XE");
>        props.put("TestPU.username", "username");
>        props.put("TestPU.password", "password");
>
>        Context ctx = new InitialContext(props);
>        HellowWorldLocal svc = (HellowWorldLocal)
> ctx.lookup(HellowWorldBean.class.getSimpleName() + "Local");
>        String key = "test-persistence-"+System.currentTimeMillis();
>
>        svc.createObject(key);
>    }
> }
>
> @Stateless
> public class HellowWorldBean implements HellowWorldLocal {
>
>    @PersistenceContext(unitName = "TestPU")
>    private EntityManager em;
>
>    /** local interface */
>    public void createObject(String parameter) {
>        Tester tester  = new Tester();
>        tester.setId(parameter);
>        T2 t2 = new T2();
>        t2.setId(parameter+System.currentTimeMillis());
>        tester.setT2(t2);
>        em.persist(tester);
>    }
> }
>
> @Entity
> @Table(name="TESTER")
> public class Tester implements java.io.Serializable {
>    @Id
>    @Column(name="id")
>    private String id;
>
>    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
>    @JoinColumn(name = "T2_FK")
>    private T2 T2 = null;
>
>    public void setId(String id) {
>        this.id = id;
>    }
>
>    public String getId() {
>        return this.id;
>    }
>
>    public void setT2(T2 t2) {
>        this.T2 = t2;
>    }
>    public T2 getT2() {
>        return this.T2;
>    }
> }
>
> @Entity
> @Table(name="T2")
> public class T2 implements java.io.Serializable {
>    @Id
>    private String id;
>
>    @OneToOne(mappedBy = "T2")
>    private Tester tester;
>
>    public void setId(String id) {
>        this.id = id;
>    }
>
>    public String getId() {
>        return this.id;
>    }
>
>    public void setTester(Tester tester) {
>        this.tester = tester;
>    }
>    public Tester getTester() {
>        return this.tester;
>    }
> }
>
>
>
>
>
> -- 
> View this message in context: http://old.nabble.com/When-using-EclipseLink-javaagent%2C-EntityManager-is-unable-to-open-a-connection-to-DB-tp26515795p26515795.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>