Example usage for org.hibernate.jpa.boot.internal PersistenceXmlParser locatePersistenceUnits

List of usage examples for org.hibernate.jpa.boot.internal PersistenceXmlParser locatePersistenceUnits

Introduction

In this page you can find the example usage for org.hibernate.jpa.boot.internal PersistenceXmlParser locatePersistenceUnits.

Prototype

public static List<ParsedPersistenceXmlDescriptor> locatePersistenceUnits(Map integration) 

Source Link

Document

Find all persistence-units from all accessible META-INF/persistence.xml resources

Usage

From source file:org.keycloak.connections.jpa.util.JpaUtils.java

License:Apache License

public static EntityManagerFactory createEntityManagerFactory(KeycloakSession session, String unitName,
        Map<String, Object> properties, boolean jta) {
    PersistenceUnitTransactionType txType = jta ? PersistenceUnitTransactionType.JTA
            : PersistenceUnitTransactionType.RESOURCE_LOCAL;
    List<ParsedPersistenceXmlDescriptor> persistenceUnits = PersistenceXmlParser
            .locatePersistenceUnits(properties);
    for (ParsedPersistenceXmlDescriptor persistenceUnit : persistenceUnits) {
        if (persistenceUnit.getName().equals(unitName)) {
            List<Class<?>> providedEntities = getProvidedEntities(session);
            for (Class<?> entityClass : providedEntities) {
                // Add all extra entity classes to the persistence unit.
                persistenceUnit.addClasses(entityClass.getName());
            }//from w  ww  . j av a2  s.c o  m
            // Now build the entity manager factory, supplying a proxy classloader, so Hibernate will be able
            // to find and load the extra provided entities.
            persistenceUnit.setTransactionType(txType);
            return Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, properties,
                    new ProxyClassLoader(providedEntities)).build();
        }
    }
    throw new RuntimeException("Persistence unit '" + unitName + "' not found");
}