Issue Details (XML | Word | Printable)

Key: GLASSFISH-1575
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: tware
Reporter: alexs12345678
Votes: 2
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
glassfish

Create more than one EntityManagerFactory for the same PersistenceUnit

Created: 24/Nov/06 06:21 AM   Updated: 06/Mar/12 10:06 PM
Component/s: entity-persistence
Affects Version/s: 9.1pe
Fix Version/s: not determined

Time Tracking:
Not Specified

Environment:

Operating System: All
Platform: All


Issuezilla Id: 1,575
Tags:
Participants: ailitche, alexs12345678, antodasana, franos13, marina vatkina, Tom Mueller and tware


 Description  « Hide

Hi,

when I try to create more than one EntityManagerFactory for the same
PesistenceUnit (to use different user/passwords for login) I run into the
problem that toplink only creates only one EntityManagerFactory and returns it
via Persistence.createEntityManagerFactory(..) even if I use a different
properties object.

I use the following code:

Map<String, String> connectProps1 = new HashMap<String, String>();
connectProps1.put(TopLinkProperties.JDBC_USER, "user1");
connectProps1.put(TopLinkProperties.JDBC_PASSWORD,"password1");

EntityManagerFactory myemf1 = Persistence.createEntityManagerFactory("default",
connectProps1);

EntityManager em1 = myemf1.createEntityManager();

List userstring1 = em1.createNativeQuery("select user from dual").getResultList
();
String usi1 = userstring1.toString();
System.out.println(usi1);

Map<String, String> connectProps2 = new HashMap<String, String>();
connectProps2.put(TopLinkProperties.JDBC_USER, "user2");
connectProps2.put(TopLinkProperties.JDBC_PASSWORD,"password2");

EntityManagerFactory myemf2 = Persistence.createEntityManagerFactory("default",
connectProps2);

EntityManager em2 = myemf2.createEntityManager();

List userstring2 = em2.createNativeQuery("select user from dual").getResultList
();
String usi2 = userstring2.toString();
System.out.println(usi2);

But Toplink essentials does only creates one EntityManagerFactory (when
executing myemf1.createEntityManager() I think ) and starts the database
connections, but the second Persistence.createEntityManagerFactory("default",
connectProps2) call seems to be ignored.
The result from "select user from dual" is in both cases "user1"

By the way:
It seems that Hibernate can create more than one EntityManagerFactory per
PesistenceUnit.

Best regards and thanks for any feedback,
Alex Schaefer