use of org.keycloak.connections.jpa.entityprovider.ProxyClassLoader in project keycloak by keycloak.
the class JpaUtils method createEntityManagerFactory.
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());
}
// 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");
}
Aggregations