I work with JPA2 and I use a multiple persistence unit configuration that is represented in my persistence.xml, like this:
<?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>
Is there any method to extract persistence unit names from persistence.xml programmatically (using Hibernate or JPA2)? Like this:
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);
But I need to read not only properties.