|
33 | 33 | import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
|
34 | 34 | import org.hibernate.boot.cfgxml.spi.LoadedConfig;
|
35 | 35 | import org.hibernate.boot.cfgxml.spi.MappingReference;
|
| 36 | +import org.hibernate.boot.model.convert.spi.ConverterDescriptor; |
36 | 37 | import org.hibernate.boot.model.process.spi.ManagedResources;
|
37 | 38 | import org.hibernate.boot.model.process.spi.MetadataBuildingProcess;
|
38 | 39 | import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
@@ -222,80 +223,87 @@ private EntityManagerFactoryBuilderImpl(
|
222 | 223 | providedClassLoader,
|
223 | 224 | providedClassLoaderService
|
224 | 225 | );
|
| 226 | + try { |
| 227 | + // merge configuration sources and build the "standard" service registry |
| 228 | + final StandardServiceRegistryBuilder ssrBuilder = getStandardServiceRegistryBuilder( bsr ); |
225 | 229 |
|
226 |
| - // merge configuration sources and build the "standard" service registry |
227 |
| - final StandardServiceRegistryBuilder ssrBuilder = getStandardServiceRegistryBuilder( bsr ); |
228 |
| - |
229 |
| - final MergedSettings mergedSettings = mergeSettings( persistenceUnit, integrationSettings, ssrBuilder ); |
| 230 | + final MergedSettings mergedSettings = mergeSettings( persistenceUnit, integrationSettings, ssrBuilder ); |
230 | 231 |
|
231 |
| - // flush before completion validation |
232 |
| - if ( "true".equals( mergedSettings.configurationValues.get( Environment.FLUSH_BEFORE_COMPLETION ) ) ) { |
233 |
| - LOG.definingFlushBeforeCompletionIgnoredInHem( Environment.FLUSH_BEFORE_COMPLETION ); |
234 |
| - mergedSettings.configurationValues.put( Environment.FLUSH_BEFORE_COMPLETION, "false" ); |
235 |
| - } |
| 232 | + // flush before completion validation |
| 233 | + if ( "true".equals( mergedSettings.configurationValues.get( Environment.FLUSH_BEFORE_COMPLETION ) ) ) { |
| 234 | + LOG.definingFlushBeforeCompletionIgnoredInHem( Environment.FLUSH_BEFORE_COMPLETION ); |
| 235 | + mergedSettings.configurationValues.put( Environment.FLUSH_BEFORE_COMPLETION, "false" ); |
| 236 | + } |
236 | 237 |
|
237 |
| - // keep the merged config values for phase-2 |
238 |
| - this.configurationValues = mergedSettings.getConfigurationValues(); |
| 238 | + // keep the merged config values for phase-2 |
| 239 | + this.configurationValues = mergedSettings.getConfigurationValues(); |
239 | 240 |
|
240 |
| - // Build the "standard" service registry |
241 |
| - ssrBuilder.applySettings( configurationValues ); |
| 241 | + // Build the "standard" service registry |
| 242 | + ssrBuilder.applySettings( configurationValues ); |
242 | 243 |
|
243 |
| - this.standardServiceRegistry = ssrBuilder.build(); |
| 244 | + this.standardServiceRegistry = ssrBuilder.build(); |
244 | 245 |
|
245 |
| - configureIdentifierGenerators( standardServiceRegistry ); |
| 246 | + configureIdentifierGenerators( standardServiceRegistry ); |
246 | 247 |
|
247 |
| - final MetadataSources metadataSources = new MetadataSources( bsr ); |
248 |
| - List<AttributeConverterDefinition> attributeConverterDefinitions = applyMappingResources( metadataSources ); |
| 248 | + final MetadataSources metadataSources = new MetadataSources( bsr ); |
| 249 | + this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder( standardServiceRegistry ); |
| 250 | + List<AttributeConverterDefinition> attributeConverterDefinitions = applyMappingResources( metadataSources ); |
249 | 251 |
|
250 |
| - this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder( standardServiceRegistry ); |
251 |
| - applyMetamodelBuilderSettings( mergedSettings, attributeConverterDefinitions ); |
| 252 | + applyMetamodelBuilderSettings( mergedSettings, attributeConverterDefinitions ); |
252 | 253 |
|
253 |
| - applyMetadataBuilderContributor(); |
| 254 | + applyMetadataBuilderContributor(); |
254 | 255 |
|
255 |
| - // todo : would be nice to have MetadataBuilder still do the handling of CfgXmlAccessService here |
256 |
| - // another option is to immediately handle them here (probably in mergeSettings?) as we encounter them... |
257 |
| - final CfgXmlAccessService cfgXmlAccessService = standardServiceRegistry.getService( CfgXmlAccessService.class ); |
258 |
| - if ( cfgXmlAccessService.getAggregatedConfig() != null ) { |
259 |
| - if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) { |
260 |
| - for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig().getMappingReferences() ) { |
261 |
| - mappingReference.apply( metadataSources ); |
| 256 | + // todo : would be nice to have MetadataBuilder still do the handling of CfgXmlAccessService here |
| 257 | + // another option is to immediately handle them here (probably in mergeSettings?) as we encounter them... |
| 258 | + final CfgXmlAccessService cfgXmlAccessService = standardServiceRegistry.getService( CfgXmlAccessService.class ); |
| 259 | + if ( cfgXmlAccessService.getAggregatedConfig() != null ) { |
| 260 | + if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) { |
| 261 | + for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig() |
| 262 | + .getMappingReferences() ) { |
| 263 | + mappingReference.apply( metadataSources ); |
| 264 | + } |
262 | 265 | }
|
263 | 266 | }
|
264 |
| - } |
265 | 267 |
|
266 |
| - this.managedResources = MetadataBuildingProcess.prepare( |
267 |
| - metadataSources, |
268 |
| - metamodelBuilder.getBootstrapContext() |
269 |
| - ); |
| 268 | + this.managedResources = MetadataBuildingProcess.prepare( |
| 269 | + metadataSources, |
| 270 | + metamodelBuilder.getBootstrapContext() |
| 271 | + ); |
270 | 272 |
|
271 |
| - final Object validatorFactory = configurationValues.get( org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY ); |
272 |
| - if ( validatorFactory == null ) { |
273 |
| - withValidatorFactory( configurationValues.get( org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY ) ); |
274 |
| - } |
275 |
| - else { |
276 |
| - withValidatorFactory( validatorFactory ); |
277 |
| - } |
| 273 | + final Object validatorFactory = configurationValues.get( org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY ); |
| 274 | + if ( validatorFactory == null ) { |
| 275 | + withValidatorFactory( configurationValues.get( org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY ) ); |
| 276 | + } |
| 277 | + else { |
| 278 | + withValidatorFactory( validatorFactory ); |
| 279 | + } |
278 | 280 |
|
279 |
| - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
280 |
| - // push back class transformation to the environment; for the time being this only has any effect in EE |
281 |
| - // container situations, calling back into PersistenceUnitInfo#addClassTransformer |
| 281 | + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 282 | + // push back class transformation to the environment; for the time being this only has any effect in EE |
| 283 | + // container situations, calling back into PersistenceUnitInfo#addClassTransformer |
282 | 284 |
|
283 |
| - final boolean dirtyTrackingEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING ); |
284 |
| - final boolean lazyInitializationEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION ); |
285 |
| - final boolean associationManagementEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT ); |
| 285 | + final boolean dirtyTrackingEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING ); |
| 286 | + final boolean lazyInitializationEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION ); |
| 287 | + final boolean associationManagementEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT ); |
286 | 288 |
|
287 |
| - if ( dirtyTrackingEnabled || lazyInitializationEnabled || associationManagementEnabled ) { |
288 |
| - EnhancementContext enhancementContext = getEnhancementContext( |
289 |
| - dirtyTrackingEnabled, |
290 |
| - lazyInitializationEnabled, |
291 |
| - associationManagementEnabled |
292 |
| - ); |
| 289 | + if ( dirtyTrackingEnabled || lazyInitializationEnabled || associationManagementEnabled ) { |
| 290 | + EnhancementContext enhancementContext = getEnhancementContext( |
| 291 | + dirtyTrackingEnabled, |
| 292 | + lazyInitializationEnabled, |
| 293 | + associationManagementEnabled |
| 294 | + ); |
293 | 295 |
|
294 |
| - persistenceUnit.pushClassTransformer( enhancementContext ); |
295 |
| - } |
| 296 | + persistenceUnit.pushClassTransformer( enhancementContext ); |
| 297 | + } |
296 | 298 |
|
297 |
| - // for the time being we want to revoke access to the temp ClassLoader if one was passed |
298 |
| - metamodelBuilder.applyTempClassLoader( null ); |
| 299 | + // for the time being we want to revoke access to the temp ClassLoader if one was passed |
| 300 | + metamodelBuilder.applyTempClassLoader( null ); |
| 301 | + } |
| 302 | + catch (Throwable t) { |
| 303 | + bsr.close(); |
| 304 | + cleanup(); |
| 305 | + throw t; |
| 306 | + } |
299 | 307 | }
|
300 | 308 |
|
301 | 309 | /**
|
@@ -532,8 +540,9 @@ private MergedSettings mergeSettings(
|
532 | 540 | if ( keyString.startsWith( JACC_PREFIX ) ) {
|
533 | 541 | if( !JACC_CONTEXT_ID.equals( keyString ) && !JACC_ENABLED.equals( keyString )) {
|
534 | 542 | if ( jaccContextId == null ) {
|
535 |
| - LOG.debug( |
536 |
| - "Found JACC permission grant [%s] in properties, but no JACC context id was specified; ignoring" |
| 543 | + LOG.debugf( |
| 544 | + "Found JACC permission grant [%s] in properties, but no JACC context id was specified; ignoring", |
| 545 | + keyString |
537 | 546 | );
|
538 | 547 | }
|
539 | 548 | else {
|
@@ -716,7 +725,7 @@ else if ( persistenceUnit.getTransactionType() != null ) {
|
716 | 725 |
|
717 | 726 | if ( txnType == null ) {
|
718 | 727 | // is it more appropriate to have this be based on bootstrap entry point (EE vs SE)?
|
719 |
| - LOG.debugf( "PersistenceUnitTransactionType not specified - falling back to RESOURCE_LOCAL" ); |
| 728 | + LOG.debug( "PersistenceUnitTransactionType not specified - falling back to RESOURCE_LOCAL" ); |
720 | 729 | txnType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
|
721 | 730 | }
|
722 | 731 |
|
|
0 commit comments