0

私は JPA2 を使用しており、次のように、persistence.xml で表される複数の永続ユニット構成を使用しています。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0">                           
  <persistence-unit name="FirstPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>entities.Book</class>
    <properties>        
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
      ...
    </properties>
  </persistence-unit>  
  <persistence-unit name="SecondPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>entities.Book</class>
    <properties>        
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
      ...
    </properties>
  </persistence-unit>  
</persistence>

プログラムで (Hibernate または JPA2 を使用して) persistence.xml から永続ユニット名を抽出する方法はありますか? このような:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");

// or

Map<String, Object> configOverrides = new HashMap<String, Object>();
configOverrides.put("hibernate.hbm2ddl.auto", "create-drop");
EntityManagerFactory programmaticEmf =
    Persistence.createEntityManagerFactory("manager1", configOverrides);

しかし、プロパティだけでなく読み取る必要があります。

4

0 に答える 0