diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ScanningCoordinator.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ScanningCoordinator.java index bd8b525e64..04e34f0bfc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ScanningCoordinator.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ScanningCoordinator.java @@ -203,23 +203,24 @@ public class ScanningCoordinator { nonLocatedMappingFileNames.addAll( explicitMappingFileNames ); } - for ( MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles() ) { - 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 ) - ); + if ( xmlMappingBinderAccess != null ) { // xml mapping is not disabled + for ( MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles() ) { + managedResources.addXmlBinding( xmlMappingBinderAccess.bind( mappingFileDescriptor.getStreamAccess() ) ); + nonLocatedMappingFileNames.remove( mappingFileDescriptor.getName() ); } - 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java index 8221eff0b3..6b40eac9ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java @@ -294,28 +294,30 @@ public class MetadataBuildingProcess { metadataCollector.processSecondPasses( rootMetadataBuildingContext ); - Iterable producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class ); - if ( producers != null ) { - final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder(); -// final MappingBinder mappingBinder = new MappingBinder( true ); - // We need to disable validation here. It seems Envers is not producing valid (according to schema) XML - final MappingBinder mappingBinder = options.isXmlMappingEnabled() ? new MappingBinder( classLoaderService, false ) : null; - for ( AdditionalJaxbMappingProducer producer : producers ) { - log.tracef( "Calling AdditionalJaxbMappingProducer : %s", producer ); - Collection additionalMappings = producer.produceAdditionalMappings( - metadataCollector, - jandexView, - mappingBinder, - rootMetadataBuildingContext - ); - for ( MappingDocument mappingDocument : additionalMappings ) { - hierarchyBuilder.indexMappingDocument( mappingDocument ); + if ( options.isXmlMappingEnabled() ) { + Iterable producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class ); + if ( producers != null ) { + final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder(); + // final MappingBinder mappingBinder = new MappingBinder( true ); + // We need to disable validation here. It seems Envers is not producing valid (according to schema) XML + final MappingBinder mappingBinder = new MappingBinder( classLoaderService, false ); + for ( AdditionalJaxbMappingProducer producer : producers ) { + log.tracef( "Calling AdditionalJaxbMappingProducer : %s", producer ); + Collection additionalMappings = producer.produceAdditionalMappings( + metadataCollector, + jandexView, + mappingBinder, + rootMetadataBuildingContext + ); + for ( MappingDocument mappingDocument : additionalMappings ) { + hierarchyBuilder.indexMappingDocument( mappingDocument ); + } } - } - ModelBinder binder = ModelBinder.prepare( rootMetadataBuildingContext ); - for ( EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies() ) { - binder.bindEntityHierarchy( entityHierarchySource ); + ModelBinder binder = ModelBinder.prepare( rootMetadataBuildingContext ); + for ( EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies() ) { + binder.bindEntityHierarchy( entityHierarchySource ); + } } }