HHH-8121 - Make property-able JPA settings defined in persistence.xml available in EMF.getProperties()

This commit is contained in:
Steve Ebersole 2013-04-02 20:39:37 -05:00
parent 076e17e5b1
commit ea8f587800
1 changed files with 18 additions and 4 deletions

View File

@ -832,7 +832,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
sessionFactory.addObserver( new ServiceRegistryCloser() ); sessionFactory.addObserver( new ServiceRegistryCloser() );
// NOTE : passing cfg is temporary until // NOTE : passing cfg is temporary until
return new EntityManagerFactoryImpl( persistenceUnit.getName(), sessionFactory, settings, configurationValues, hibernateConfiguration ); return new EntityManagerFactoryImpl(
persistenceUnit.getName(),
sessionFactory,
settings,
configurationValues,
hibernateConfiguration
);
} }
} }
); );
@ -906,13 +912,21 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
private void applyJdbcConnectionProperties() { private void applyJdbcConnectionProperties() {
if ( dataSource != null ) { if ( dataSource != null ) {
serviceRegistryBuilder.applySetting( Environment.DATASOURCE, dataSource ); serviceRegistryBuilder.applySetting( org.hibernate.cfg.AvailableSettings.DATASOURCE, dataSource );
} }
else if ( persistenceUnit.getJtaDataSource() != null ) { else if ( persistenceUnit.getJtaDataSource() != null ) {
serviceRegistryBuilder.applySetting( Environment.DATASOURCE, persistenceUnit.getJtaDataSource() ); if ( ! serviceRegistryBuilder.getSettings().containsKey( org.hibernate.cfg.AvailableSettings.DATASOURCE ) ) {
serviceRegistryBuilder.applySetting( org.hibernate.cfg.AvailableSettings.DATASOURCE, persistenceUnit.getJtaDataSource() );
// HHH-8121 : make the PU-defined value available to EMF.getProperties()
configurationValues.put( AvailableSettings.JTA_DATASOURCE, persistenceUnit.getJtaDataSource() );
}
} }
else if ( persistenceUnit.getNonJtaDataSource() != null ) { else if ( persistenceUnit.getNonJtaDataSource() != null ) {
serviceRegistryBuilder.applySetting( Environment.DATASOURCE, persistenceUnit.getNonJtaDataSource() ); if ( ! serviceRegistryBuilder.getSettings().containsKey( org.hibernate.cfg.AvailableSettings.DATASOURCE ) ) {
serviceRegistryBuilder.applySetting( org.hibernate.cfg.AvailableSettings.DATASOURCE, persistenceUnit.getNonJtaDataSource() );
// HHH-8121 : make the PU-defined value available to EMF.getProperties()
configurationValues.put( AvailableSettings.NON_JTA_DATASOURCE, persistenceUnit.getNonJtaDataSource() );
}
} }
else { else {
final String driver = (String) configurationValues.get( AvailableSettings.JDBC_DRIVER ); final String driver = (String) configurationValues.get( AvailableSettings.JDBC_DRIVER );