HHH-8636 Wrapping all exceptions into PersistenceException in HibernatePersistenceProvider

This commit is contained in:
Gunnar Morling 2013-10-25 23:49:23 +02:00 committed by Steve Ebersole
parent e135566c0e
commit 485096a78b
1 changed files with 15 additions and 10 deletions

View File

@ -64,6 +64,7 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
log.tracef( "Starting createEntityManagerFactory for persistenceUnitName %s", persistenceUnitName );
try {
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties );
if ( builder == null ) {
log.trace( "Could not obtain matching EntityManagerFactoryBuilder, returning null" );
@ -73,6 +74,14 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
return builder.build();
}
}
catch (PersistenceException pe) {
throw pe;
}
catch (Exception e) {
log.debug( "Unable to build entity manager factory", e );
throw new PersistenceException( "Unable to build entity manager factory", e );
}
}
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties) {
return getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties, null );
@ -86,10 +95,6 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
try {
units = PersistenceXmlParser.locatePersistenceUnits( integration );
}
catch (RuntimeException e) {
log.debug( "Unable to locate persistence units", e );
throw e;
}
catch (Exception e) {
log.debug( "Unable to locate persistence units", e );
throw new PersistenceException( "Unable to locate persistence units", e );