[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] multiple EntityManagers in one process
|
----- Original Message -----
Sent: Thursday, May 21, 2009 10:31 AM
Subject: Re: [eclipselink-users] multiple EntityManagers in
one process
> OK, after asking that question, I found the following
thread:
> http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg02625.html>
> So this is my understanding:
>
> A singleton
ServerSession is associated with a named persistence unit.
> Any
EntityManagerFactory/EntityManager created under that PU name will
> share the same ServerSession.
>
> Is this
correct?
Yes.
>
> I need to create a schema associated with my
existing PU in the new
> database. Is it possible to create a new
PersistenceUnit name on the
> fly?
>
If you don't need the two ServerSessions connected
simultaneously you can re-use the same ServerSession:
Map prop1 = new HashMap();
// populate prop1
EntityManagerFactory factory1 =
persistence.createEntityManagerFactory("MyPU", prop1);
...
factory1.close();
Map prop2 = new HashMap();
// populate prop2
EntityManagerFactory factory2 =
persistence.createEntityManagerFactory("MyPU", prop2);
...
If you need two ServerSessions to co-exist, try using
"eclipselink.session-name" property:
Map prop1 = new HashMap();
// populate
prop1
prop1.put("eclipselink.session-name",
"session1");
EntityManagerFactory factory1 =
persistence.createEntityManagerFactory("MyPU", prop1);
Map prop2 = new HashMap();
// populate
prop2
prop2.put("eclipselink.session-name",
"session2");
EntityManagerFactory factory2 =
persistence.createEntityManagerFactory("MyPU", prop2);
I believe that should work but couldn't find a test and haven't tried it
myself.
Thanks,
Andrei
> On May 20, 2009, at 4:08
PM, David Parker wrote:
>
>> I am trying to build a schema
migration functionality that requires
>> separate connections to
different databases.
>>
>> What is happening is that the first
entitymanagerfactory is
>> initialized, connected to its
database. Then I create another
>> entitymanagerfactory with a
different set of connection properties,
>>
using
>>
>> public static String
JPA_DRIVER_PROP = "eclipselink.jdbc.driver";
>>
public static String JPA_URL_PROP =
"eclipselink.jdbc.url";
>> public static String
JPA_USER_PROP = "eclipselink.jdbc.user";
>> public
static String JPA_PASSWORD_PROP =
>>
"eclipselink.jdbc.password";
>>
>> property names. Despite
creating a "new" EntityManagerFactory object
>> with a different
set of properties, it still connects to the
>> original
database, i.e., it has the same connection information
>>
internally as the original entitymanagerfactory. I notice that it
>> shares the same DatabaseAccessor object.
>>
>>
I'm clearly not understanding how this is supposed to work. What is
>> the correct way to go about maintaining connections to
separate
>> databases?
>>
>>
Thanks.
>>
>>
=============================================
>> David
Parker
>> dap@xxxxxxxxxxxxxxxxxxxx>>
>>
>>
>>
>>
_______________________________________________
>> eclipselink-users
mailing list
>> eclipselink-users@xxxxxxxxxxx>>
https://dev.eclipse.org/mailman/listinfo/eclipselink-users>>
>
>
=============================================
> David Parker
>
dap@xxxxxxxxxxxxxxxxxxxx>
>
>
>
>
_______________________________________________
> eclipselink-users
mailing list
> eclipselink-users@xxxxxxxxxxx> https://dev.eclipse.org/mailman/listinfo/eclipselink-users>