Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-7474

create a new persistence unit programmatically and map it to a new datasource without redeploy or server restart

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Obsolete
    • Icon: Major Major
    • No Release
    • JBossAS-5.1.0.GA
    • JPA / Hibernate
    • None
    • JBoss 5.1.0.GA

      Currently we use the persistence.xml to map a persistenceUnit to data source. Our application got a requirement:

      create a new persistence unit programmatically and map it to a new datasource without redeploy or server restart. How to achieve this functionality?

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");
      //or
      Map configOverrides = new HashMap();
      configOverrides.put("hibernate.hbm2ddl.auto", "create-drop");
      EntityManagerFactory programmaticEmf =
      Persistence.createEntityManagerFactory("manager1", configOverrides);

      But the persistence unit "manager1" needs to be defined in persistence.xml.

      What we need is:

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo", "dataSourceName");
      the persistence unit "foo" is not defined in any persistence.xml.

              sebersole Steve Ebersole (Inactive)
              javatwo_jira Dave Chen (Inactive)
              Votes:
              2 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: