[prev in list] [next in list] [prev in thread] [next in thread]
List: openejb-user
Subject: When using EclipseLink javaagent, EntityManager is unable to open a
From: babstr <babster_vt () yahoo ! com>
Date: 2009-11-25 16:26:59
Message-ID: 26515795.post () talk ! nabble ! com
[Download RAW message or body]
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.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic