I think I have found the issue. My Entity Manager Factory object was
a local variable. I made it a class member and it seems to work.
Probably the emf object was being garbage collected.
My Bad...
Thanks anyways
Rohit
On 2/23/2011 9:23 PM, Tom Ware wrote:
Hi
Rohit,
Have you tried your code with a standard data source? The
exception does not initially appear to be data source related?
-Tom
Rohit Banga wrote:
Hi All
In an effort to allow sharing of a connection pool across
different configurations (serverSessions), I am trying to use
Universal Connection Pool with Eclipselink. I am able to get the
basic functionality working using something like below:
1. Create a PoolDataSource
a. set the datasource parameters
2. set the PersistenceProvider using the following code:
PersistenceProviderResolverHolder.setPersistenceProviderResolver(
new MyPersistenceProviderResolver()); }
...
static class MyPersistenceProviderResolver implements
PersistenceProviderResolver {
public List<PersistenceProvider>
getPersistenceProviders() {
List<PersistenceProvider> providers = new
ArrayList<PersistenceProvider>();
providers.add(new MyPersistenceProvider());
return providers;
}
public void clearCachedProviders() { }
}
...
static class MyPersistenceProvider implements
PersistenceProvider {
public EntityManagerFactory
createContainerEntityManagerFactory(
PersistenceUnitInfo info,
@SuppressWarnings("rawtypes")Map map) {
return null;
}
public EntityManagerFactory
createEntityManagerFactory(String emName,
@SuppressWarnings("rawtypes")Map map) {
SEPersistenceUnitInfo puInfo = new
SEPersistenceUnitInfo();
URL noopURL = null;
try {
noopURL = new URL(null, "noop:", new
URLStreamHandler() {
protected URLConnection openConnection(URL
url) throws IOException {
return new URLConnection(url) {
public InputStream getInputStream()
throws IOException {
return null;
}
public void connect() throws
IOException {
}
};
}
});
}
catch (Exception e) {
e.printStackTrace();
}
puInfo.setPersistenceUnitRootUrl(noopURL);
EntityManagerSetupImpl entityManagerSetupImpl =
new EntityManagerSetupImpl(PERSISTENCE_UNIT_NAME
+ Math.random(), PERSISTENCE_UNIT_NAME + Math.random());
entityManagerSetupImpl.predeploy(puInfo, map);
return new
EntityManagerFactoryImpl(entityManagerSetupImpl, map);
}
public ProviderUtil getProviderUtil() {
return null;
}
}
3. Create the configuration with the following types:
EmpDep ed = new EmpDep();
Order order = new Order();
the Order constructor creates a serverSession which has a
reference to a DynamicType for "Order" table.
the EmpDep constructor creates a serverSession which has a
reference to DynamicTypes for "Employee", "Department" tables
and their relationships.
Both these objects are connected to the same Datasource
using
properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE,
datasource);
These classes have a printAll() method which does a SELECT *
on the tables. It acquires a client session to execute the query
and then releases it.
4. Now I do the following
order.printAll();
ed.printAll();
5. *The above code flow goes through fine. But if I swap the
order of initialization of the ed and order objects, I get the
following exception*:
Query Key empinfo.depinfo
Base jpatest.empinfo is not valid, or for a mapping type that
does not support joining.
at
org.eclipse.persistence.exceptions.QueryException.mappingForExpressionDoesNotSupportJoining(QueryException.java:673)
at
org.eclipse.persistence.internal.queries.JoinedAttributeManager.prepareJoinExpression(JoinedAttributeManager.java:851)
To sum it up:
A.
EmpDep ed = new EmpDep();
Order order = new Order();
order.printAll();
ed.printAll();
works
B.
Order order = new Order();
EmpDep ed = new EmpDep();
order.printAll();
ed.printAll();
does not work
C.
EmpDep ed = new EmpDep();
Order order = new Order();
ed.printAll();
order.printAll();
does not work
D.
EmpDep ed = new EmpDep();
Order order = new Order();
order.printAll();
ed.printAll();
order.printAll(); // throws an error that we should log into
the session first.
Any idea why this behavior with the third party datasource also?
--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies
|