glassfish
  1. glassfish
  2. GLASSFISH-1575

Create more than one EntityManagerFactory for the same PersistenceUnit

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 9.1pe
    • Fix Version/s: not determined
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      1,575

      Description

      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

        Activity

          People

          • Assignee:
            tware
            Reporter:
            alexs12345678
          • Votes:
            2 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: