HHH-14356 Avoid NPE when booting with xml_mapping_enabled=false

Introduced by HHH-14334
when use Envers with hibernate.xml_mapping_enabled=false
see 34151a9660 (r44735539)
This commit is contained in:
Yanming Zhou 2020-12-03 10:44:12 +08:00 committed by Sanne Grinovero
parent 0009fec578
commit 04c97c2293
2 changed files with 38 additions and 35 deletions

View File

@ -203,23 +203,24 @@ public class ScanningCoordinator {
nonLocatedMappingFileNames.addAll( explicitMappingFileNames ); nonLocatedMappingFileNames.addAll( explicitMappingFileNames );
} }
for ( MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles() ) { if ( xmlMappingBinderAccess != null ) { // xml mapping is not disabled
managedResources.addXmlBinding( xmlMappingBinderAccess.bind( mappingFileDescriptor.getStreamAccess() ) ); for ( MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles() ) {
nonLocatedMappingFileNames.remove( mappingFileDescriptor.getName() ); managedResources.addXmlBinding( xmlMappingBinderAccess.bind( mappingFileDescriptor.getStreamAccess() ) );
} nonLocatedMappingFileNames.remove( mappingFileDescriptor.getName() );
for ( String name : nonLocatedMappingFileNames ) {
final URL url = classLoaderService.locateResource( name );
if ( url == null ) {
throw new MappingException(
"Unable to resolve explicitly named mapping-file : " + name,
new Origin( SourceType.RESOURCE, name )
);
} }
final UrlInputStreamAccess inputStreamAccess = new UrlInputStreamAccess( url );
managedResources.addXmlBinding( xmlMappingBinderAccess.bind( inputStreamAccess ) );
}
for ( String name : nonLocatedMappingFileNames ) {
final URL url = classLoaderService.locateResource( name );
if ( url == null ) {
throw new MappingException(
"Unable to resolve explicitly named mapping-file : " + name,
new Origin( SourceType.RESOURCE, name )
);
}
final UrlInputStreamAccess inputStreamAccess = new UrlInputStreamAccess( url );
managedResources.addXmlBinding( xmlMappingBinderAccess.bind( inputStreamAccess ) );
}
}
// classes and packages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // classes and packages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -294,28 +294,30 @@ public class MetadataBuildingProcess {
metadataCollector.processSecondPasses( rootMetadataBuildingContext ); metadataCollector.processSecondPasses( rootMetadataBuildingContext );
Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class ); if ( options.isXmlMappingEnabled() ) {
if ( producers != null ) { Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class );
final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder(); if ( producers != null ) {
// final MappingBinder mappingBinder = new MappingBinder( true ); final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
// We need to disable validation here. It seems Envers is not producing valid (according to schema) XML // final MappingBinder mappingBinder = new MappingBinder( true );
final MappingBinder mappingBinder = options.isXmlMappingEnabled() ? new MappingBinder( classLoaderService, false ) : null; // We need to disable validation here. It seems Envers is not producing valid (according to schema) XML
for ( AdditionalJaxbMappingProducer producer : producers ) { final MappingBinder mappingBinder = new MappingBinder( classLoaderService, false );
log.tracef( "Calling AdditionalJaxbMappingProducer : %s", producer ); for ( AdditionalJaxbMappingProducer producer : producers ) {
Collection<MappingDocument> additionalMappings = producer.produceAdditionalMappings( log.tracef( "Calling AdditionalJaxbMappingProducer : %s", producer );
metadataCollector, Collection<MappingDocument> additionalMappings = producer.produceAdditionalMappings(
jandexView, metadataCollector,
mappingBinder, jandexView,
rootMetadataBuildingContext mappingBinder,
); rootMetadataBuildingContext
for ( MappingDocument mappingDocument : additionalMappings ) { );
hierarchyBuilder.indexMappingDocument( mappingDocument ); for ( MappingDocument mappingDocument : additionalMappings ) {
hierarchyBuilder.indexMappingDocument( mappingDocument );
}
} }
}
ModelBinder binder = ModelBinder.prepare( rootMetadataBuildingContext ); ModelBinder binder = ModelBinder.prepare( rootMetadataBuildingContext );
for ( EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies() ) { for ( EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies() ) {
binder.bindEntityHierarchy( entityHierarchySource ); binder.bindEntityHierarchy( entityHierarchySource );
}
} }
} }