HHH-17460 - Ongoing JPA 32 work

- mapping defaults & persistence unit defaults
This commit is contained in:
Steve Ebersole 2024-03-25 17:14:30 -05:00
parent faaece244b
commit c5f1c80040
44 changed files with 686 additions and 181 deletions

View File

@ -223,12 +223,12 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector,
MetadataBuildingOptions options) {
this(
bootstrapContext,
buildContext( bootstrapContext ),
createModelBuildingContext( bootstrapContext ),
options
);
}
private static SourceModelBuildingContext buildContext(BootstrapContext bootstrapContext) {
private static SourceModelBuildingContext createModelBuildingContext(BootstrapContext bootstrapContext) {
final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class );
final ClassLoaderServiceLoading classLoading = new ClassLoaderServiceLoading( classLoaderService );
return new SourceModelBuildingContextImpl(

View File

@ -10,7 +10,6 @@ import org.hibernate.boot.model.TypeDefinitionRegistryStandardImpl;
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
@ -21,7 +20,7 @@ public class MetadataBuildingContextRootImpl implements MetadataBuildingContext
private final String contributor;
private final BootstrapContext bootstrapContext;
private final MetadataBuildingOptions options;
private final MappingDefaults mappingDefaults;
private final RootMappingDefaults mappingDefaults;
private final InFlightMetadataCollector metadataCollector;
private final ObjectNameNormalizer objectNameNormalizer;
private final TypeDefinitionRegistryStandardImpl typeDefinitionRegistry;
@ -30,11 +29,12 @@ public class MetadataBuildingContextRootImpl implements MetadataBuildingContext
String contributor,
BootstrapContext bootstrapContext,
MetadataBuildingOptions options,
InFlightMetadataCollector metadataCollector) {
InFlightMetadataCollector metadataCollector,
RootMappingDefaults mappingDefaults) {
this.contributor = contributor;
this.bootstrapContext = bootstrapContext;
this.options = options;
this.mappingDefaults = options.getMappingDefaults();
this.mappingDefaults = mappingDefaults;
this.metadataCollector = metadataCollector;
this.objectNameNormalizer = new ObjectNameNormalizer() {
@Override
@ -56,7 +56,7 @@ public class MetadataBuildingContextRootImpl implements MetadataBuildingContext
}
@Override
public MappingDefaults getMappingDefaults() {
public RootMappingDefaults getEffectiveDefaults() {
return mappingDefaults;
}

View File

@ -0,0 +1,165 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.boot.internal;
import java.util.EnumSet;
import org.hibernate.annotations.CascadeType;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.boot.spi.MappingDefaults;
import jakarta.persistence.AccessType;
import static org.hibernate.internal.util.NullnessHelper.coalesce;
import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
/**
* Base set of defaults for all mappings
*
* @author Steve Ebersole
*/
public class RootMappingDefaults implements EffectiveMappingDefaults {
private final String catalog;
private final String schema;
private final boolean quoteIdentifiers;
private final String packageName;
private final boolean autoImport;
private final EnumSet<CascadeType> cascadeTypes;
private final AccessType propertyAccessType;
private final String propertyAccessStrategyName;
private final org.hibernate.cache.spi.access.AccessType cacheAccessType;
private final boolean entityLaziness;
private final boolean collectionLaziness;
private final String idColumnName;
private final String discriminatorColumnName;
private final String tenantIdColumnName;
public RootMappingDefaults(
MappingDefaults mappingDefaults,
PersistenceUnitMetadata persistenceUnitMetadata) {
this.catalog = coalesceSuppliedValues(
mappingDefaults::getImplicitCatalogName,
persistenceUnitMetadata::getDefaultCatalog
);
this.schema = coalesceSuppliedValues(
mappingDefaults::getImplicitSchemaName,
persistenceUnitMetadata::getDefaultSchema
);
// both use primitive boolean, so true when one is true
this.quoteIdentifiers = mappingDefaults.shouldImplicitlyQuoteIdentifiers()
|| persistenceUnitMetadata.useQuotedIdentifiers();
this.packageName = mappingDefaults.getImplicitPackageName();
this.autoImport = mappingDefaults.isAutoImportEnabled();
this.cascadeTypes = persistenceUnitMetadata.getDefaultCascadeTypes();
this.propertyAccessType = persistenceUnitMetadata.getAccessType();
this.propertyAccessStrategyName = coalesceSuppliedValues(
mappingDefaults::getImplicitPropertyAccessorName,
persistenceUnitMetadata::getDefaultAccessStrategyName
);
this.cacheAccessType = mappingDefaults.getImplicitCacheAccessType();
this.entityLaziness = mappingDefaults.areEntitiesImplicitlyLazy();
this.collectionLaziness = mappingDefaults.areCollectionsImplicitlyLazy();
this.idColumnName = coalesce(
mappingDefaults.getImplicitIdColumnName(),
DEFAULT_IDENTIFIER_COLUMN_NAME
);
this.discriminatorColumnName = coalesce(
mappingDefaults.getImplicitDiscriminatorColumnName(),
DEFAULT_DISCRIMINATOR_COLUMN_NAME
);
this.tenantIdColumnName = coalesce(
mappingDefaults.getImplicitTenantIdColumnName(),
DEFAULT_TENANT_IDENTIFIER_COLUMN_NAME
);
}
@Override
public String getDefaultCatalogName() {
return catalog;
}
@Override
public String getDefaultSchemaName() {
return schema;
}
@Override
public boolean isDefaultQuoteIdentifiers() {
return quoteIdentifiers;
}
@Override
public String getDefaultIdColumnName() {
return idColumnName;
}
@Override
public String getDefaultDiscriminatorColumnName() {
return discriminatorColumnName;
}
@Override
public String getDefaultTenantIdColumnName() {
return tenantIdColumnName;
}
@Override
public String getDefaultPackageName() {
return packageName;
}
@Override
public boolean isDefaultAutoImport() {
return autoImport;
}
@Override
public EnumSet<CascadeType> getDefaultCascadeTypes() {
return cascadeTypes;
}
@Override
public AccessType getDefaultPropertyAccessType() {
return propertyAccessType;
}
@Override
public String getDefaultAccessStrategyName() {
return propertyAccessStrategyName;
}
@Override
public boolean isDefaultEntityLaziness() {
return entityLaziness;
}
@Override
public boolean isDefaultCollectionLaziness() {
return collectionLaziness;
}
@Override
public org.hibernate.cache.spi.access.AccessType getDefaultCacheAccessType() {
return cacheAccessType;
}
}

View File

@ -66,7 +66,7 @@ public class AnyBinder {
}
}
bindAny(
getCascadeStrategy( null, hibernateCascade, false, forcePersist ),
getCascadeStrategy( null, hibernateCascade, false, forcePersist, context ),
//@Any has no cascade attribute
joinColumns,
onDeleteAnn == null ? null : onDeleteAnn.getEnum( "action" ),

View File

@ -966,7 +966,8 @@ public class BinderHelper {
List<jakarta.persistence.CascadeType> ejbCascades,
AnnotationUsage<Cascade> hibernateCascadeAnnotation,
boolean orphanRemoval,
boolean forcePersist) {
boolean forcePersist,
MetadataBuildingContext context) {
final EnumSet<CascadeType> cascadeTypes = convertToHibernateCascadeType( ejbCascades );
final List<CascadeType> hibernateCascades = hibernateCascadeAnnotation == null
? null
@ -981,6 +982,7 @@ public class BinderHelper {
if ( forcePersist ) {
cascadeTypes.add( CascadeType.PERSIST );
}
cascadeTypes.addAll( context.getEffectiveDefaults().getDefaultCascadeTypes() );
return renderCascadeTypeList( cascadeTypes );
}

View File

@ -513,7 +513,8 @@ public abstract class CollectionBinder {
oneToManyAnn.getList( "cascade" ),
hibernateCascade,
oneToManyAnn.getBoolean( "orphanRemoval" ),
false
false,
context
) );
collectionBinder.setOneToMany( true );
}
@ -535,7 +536,8 @@ public abstract class CollectionBinder {
manyToManyAnn.getList( "cascade" ),
hibernateCascade,
false,
false
false,
context
) );
collectionBinder.setOneToMany( false );
}
@ -546,7 +548,8 @@ public abstract class CollectionBinder {
null,
hibernateCascade,
false,
false
false,
context
) );
collectionBinder.setOneToMany( false );
}

View File

@ -109,7 +109,7 @@ public class ToOneBinder {
final AnnotationUsage<OnDelete> onDelete = property.getAnnotationUsage( OnDelete.class );
final AnnotationUsage<JoinTable> joinTable = propertyHolder.getJoinTable( property );
bindManyToOne(
getCascadeStrategy( manyToOne.getList( "cascade" ), hibernateCascade, false, forcePersist ),
getCascadeStrategy( manyToOne.getList( "cascade" ), hibernateCascade, false, forcePersist, context ),
joinColumns,
joinTable,
!isMandatory( manyToOne.getBoolean( "optional" ), property, notFoundAction ),
@ -486,7 +486,7 @@ public class ToOneBinder {
final AnnotationUsage<OnDelete> onDelete = property.getAnnotationUsage( OnDelete.class );
final AnnotationUsage<JoinTable> joinTable = propertyHolder.getJoinTable( property );
bindOneToOne(
getCascadeStrategy( oneToOne.getList( "cascade" ), hibernateCascade, oneToOne.getBoolean( "orphanRemoval" ), forcePersist ),
getCascadeStrategy( oneToOne.getList( "cascade" ), hibernateCascade, oneToOne.getBoolean( "orphanRemoval" ), forcePersist, context ),
joinColumns,
joinTable,
!isMandatory( oneToOne.getBoolean( "optional" ), property, notFoundAction ),

View File

@ -100,7 +100,7 @@ public class ImplicitNamingStrategyJpaCompliantImpl implements ImplicitNamingStr
@Override
public Identifier determineDiscriminatorColumnName(ImplicitDiscriminatorColumnNameSource source) {
return toIdentifier(
source.getBuildingContext().getMappingDefaults().getImplicitDiscriminatorColumnName(),
source.getBuildingContext().getEffectiveDefaults().getDefaultDiscriminatorColumnName(),
source.getBuildingContext()
);
}
@ -108,7 +108,7 @@ public class ImplicitNamingStrategyJpaCompliantImpl implements ImplicitNamingStr
@Override
public Identifier determineTenantIdColumnName(ImplicitTenantIdColumnNameSource source) {
return toIdentifier(
source.getBuildingContext().getMappingDefaults().getImplicitTenantIdColumnName(),
source.getBuildingContext().getEffectiveDefaults().getDefaultTenantIdColumnName(),
source.getBuildingContext()
);
}
@ -166,7 +166,7 @@ public class ImplicitNamingStrategyJpaCompliantImpl implements ImplicitNamingStr
final MetadataBuildingContext buildingContext = source.getBuildingContext();
return toIdentifier(
transformAttributePath( source.getAttributePath() )
+ "_" + buildingContext.getMappingDefaults().getImplicitDiscriminatorColumnName(),
+ "_" + buildingContext.getEffectiveDefaults().getDefaultDiscriminatorColumnName(),
buildingContext
);
}
@ -176,7 +176,7 @@ public class ImplicitNamingStrategyJpaCompliantImpl implements ImplicitNamingStr
final MetadataBuildingContext buildingContext = source.getBuildingContext();
return toIdentifier(
transformAttributePath( source.getAttributePath() )
+ "_" + buildingContext.getMappingDefaults().getImplicitIdColumnName(),
+ "_" + buildingContext.getEffectiveDefaults().getDefaultIdColumnName(),
buildingContext
);
}

View File

@ -27,6 +27,7 @@ import org.hibernate.Internal;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
import org.hibernate.boot.internal.RootMappingDefaults;
import org.hibernate.boot.jaxb.Origin;
import org.hibernate.boot.jaxb.SourceType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
@ -63,6 +64,7 @@ import org.hibernate.boot.spi.AdditionalMappingContributions;
import org.hibernate.boot.spi.AdditionalMappingContributor;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.boot.spi.MetadataContributor;
import org.hibernate.boot.spi.MetadataImplementor;
@ -193,6 +195,7 @@ public class MetadataBuildingProcess {
final MetadataBuildingOptions options) {
final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class );
assert classLoaderService != null;
final InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl( bootstrapContext, options );
handleTypes( bootstrapContext, options, metadataCollector );
@ -200,14 +203,16 @@ public class MetadataBuildingProcess {
final DomainModelSource domainModelSource = processManagedResources(
managedResources,
metadataCollector,
bootstrapContext
bootstrapContext,
options.getMappingDefaults()
);
final MetadataBuildingContextRootImpl rootMetadataBuildingContext = new MetadataBuildingContextRootImpl(
"orm",
bootstrapContext,
options,
metadataCollector
metadataCollector,
domainModelSource.getEffectiveMappingDefaults()
);
managedResources.getAttributeConverterDescriptors().forEach( metadataCollector::addAttributeConverter );
@ -220,6 +225,32 @@ public class MetadataBuildingProcess {
// to unified model
final IndexView jandexView = domainModelSource.getJandexIndex();
coordinateProcessors(
managedResources,
options,
rootMetadataBuildingContext,
domainModelSource,
classLoaderService,
metadataCollector,
jandexView
);
processAdditionalMappingContributions( metadataCollector, options, classLoaderService, rootMetadataBuildingContext );
processAdditionalJaxbMappingProducer( metadataCollector, options, jandexView, classLoaderService, rootMetadataBuildingContext );
applyExtraQueryImports( managedResources, metadataCollector );
return metadataCollector.buildMetadataInstance( rootMetadataBuildingContext );
}
private static void coordinateProcessors(
ManagedResources managedResources,
MetadataBuildingOptions options,
MetadataBuildingContextRootImpl rootMetadataBuildingContext,
DomainModelSource domainModelSource,
ClassLoaderService classLoaderService,
InFlightMetadataCollectorImpl metadataCollector,
IndexView jandexView) {
final MetadataSourceProcessor processor = new MetadataSourceProcessor() {
private final MetadataSourceProcessor hbmProcessor = options.isXmlMappingEnabled()
? new HbmMetadataSourceProcessorImpl( managedResources, rootMetadataBuildingContext )
@ -361,20 +392,14 @@ public class MetadataBuildingProcess {
processor.processNamedQueries();
processor.finishUp();
processAdditionalMappingContributions( metadataCollector, options, classLoaderService, rootMetadataBuildingContext );
processAdditionalJaxbMappingProducer( metadataCollector, options, jandexView, classLoaderService, rootMetadataBuildingContext );
applyExtraQueryImports( managedResources, metadataCollector );
return metadataCollector.buildMetadataInstance( rootMetadataBuildingContext );
}
@Internal
public static DomainModelSource processManagedResources(
ManagedResources managedResources,
InFlightMetadataCollector metadataCollector,
BootstrapContext bootstrapContext) {
BootstrapContext bootstrapContext,
MappingDefaults optionDefaults) {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// - pre-process the XML
// - collect all known classes
@ -392,7 +417,12 @@ public class MetadataBuildingProcess {
// - sourceModelBuildingContext
final SourceModelBuildingContext sourceModelBuildingContext = metadataCollector.getSourceModelBuildingContext();
final XmlPreProcessingResult xmlPreProcessingResult = XmlPreProcessor.preProcessXmlResources( managedResources );
final XmlPreProcessingResult xmlPreProcessingResult = XmlPreProcessor.preProcessXmlResources(
managedResources,
metadataCollector.getPersistenceUnitMetadata()
);
assert metadataCollector.getPersistenceUnitMetadata() == xmlPreProcessingResult.getPersistenceUnitMetadata();
//noinspection unchecked
final List<String> allKnownClassNames = mutableJoin(
@ -434,7 +464,6 @@ public class MetadataBuildingProcess {
// JPA id generator global-ity thing
final boolean areIdGeneratorsGlobal = true;
final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry();
final AnnotationDescriptorRegistry descriptorRegistry = sourceModelBuildingContext.getAnnotationDescriptorRegistry();
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
areIdGeneratorsGlobal,
metadataCollector.getGlobalRegistrations(),
@ -442,11 +471,16 @@ public class MetadataBuildingProcess {
sourceModelBuildingContext
);
final RootMappingDefaults rootMappingDefaults = new RootMappingDefaults(
optionDefaults,
xmlPreProcessingResult.getPersistenceUnitMetadata()
);
final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml(
xmlPreProcessingResult,
modelCategorizationCollector,
sourceModelBuildingContext,
bootstrapContext
bootstrapContext,
rootMappingDefaults
);
final HashSet<String> categorizedClassNames = new HashSet<>();
@ -470,6 +504,7 @@ public class MetadataBuildingProcess {
jandexIndex,
allKnownClassNames,
modelCategorizationCollector.getGlobalRegistrations(),
rootMappingDefaults,
xmlPreProcessingResult.getPersistenceUnitMetadata()
);
}
@ -718,7 +753,8 @@ public class MetadataBuildingProcess {
AnnotationMetadataSourceProcessorImpl.processAdditionalMappings(
additionalEntityClasses,
additionalJaxbMappings,
rootMetadataBuildingContext
rootMetadataBuildingContext,
options
);
}

View File

@ -6,7 +6,10 @@
*/
package org.hibernate.boot.model.source.internal;
import org.hibernate.boot.spi.MappingDefaults;
import java.util.EnumSet;
import org.hibernate.annotations.CascadeType;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.CollectionClassification;
@ -16,7 +19,7 @@ import org.hibernate.metamodel.CollectionClassification;
*
* @author Steve Ebersole
*/
public class OverriddenMappingDefaults implements MappingDefaults {
public class OverriddenMappingDefaults implements EffectiveMappingDefaults {
private final String implicitSchemaName;
private final String implicitCatalogName;
private final boolean implicitlyQuoteIdentifiers;
@ -25,7 +28,7 @@ public class OverriddenMappingDefaults implements MappingDefaults {
private final String implicitDiscriminatorColumnName;
private final String implicitPackageName;
private final boolean autoImportEnabled;
private final String implicitCascadeStyleName;
private final jakarta.persistence.AccessType implicitPropertyAccessType;
private final String implicitPropertyAccessorName;
private final boolean entitiesImplicitlyLazy;
private final boolean pluralAttributesImplicitlyLazy;
@ -42,6 +45,7 @@ public class OverriddenMappingDefaults implements MappingDefaults {
String implicitPackageName,
boolean autoImportEnabled,
String implicitCascadeStyleName,
jakarta.persistence.AccessType implicitPropertyAccessType,
String implicitPropertyAccessorName,
boolean entitiesImplicitlyLazy,
boolean pluralAttributesImplicitlyLazy,
@ -55,7 +59,7 @@ public class OverriddenMappingDefaults implements MappingDefaults {
this.implicitDiscriminatorColumnName = implicitDiscriminatorColumnName;
this.implicitPackageName = implicitPackageName;
this.autoImportEnabled = autoImportEnabled;
this.implicitCascadeStyleName = implicitCascadeStyleName;
this.implicitPropertyAccessType = implicitPropertyAccessType;
this.implicitPropertyAccessorName = implicitPropertyAccessorName;
this.entitiesImplicitlyLazy = entitiesImplicitlyLazy;
this.pluralAttributesImplicitlyLazy = pluralAttributesImplicitlyLazy;
@ -64,72 +68,77 @@ public class OverriddenMappingDefaults implements MappingDefaults {
}
@Override
public String getImplicitSchemaName() {
public String getDefaultSchemaName() {
return implicitSchemaName;
}
@Override
public String getImplicitCatalogName() {
public String getDefaultCatalogName() {
return implicitCatalogName;
}
@Override
public boolean shouldImplicitlyQuoteIdentifiers() {
public boolean isDefaultQuoteIdentifiers() {
return implicitlyQuoteIdentifiers;
}
@Override
public String getImplicitIdColumnName() {
public String getDefaultIdColumnName() {
return implicitIdColumnName;
}
@Override
public String getImplicitTenantIdColumnName() {
return implicitTenantIdColumnName;
}
@Override
public String getImplicitDiscriminatorColumnName() {
public String getDefaultDiscriminatorColumnName() {
return implicitDiscriminatorColumnName;
}
@Override
public String getImplicitPackageName() {
public String getDefaultTenantIdColumnName() {
return implicitTenantIdColumnName;
}
@Override
public String getDefaultPackageName() {
return implicitPackageName;
}
@Override
public boolean isAutoImportEnabled() {
public boolean isDefaultAutoImport() {
return autoImportEnabled;
}
@Override
public String getImplicitCascadeStyleName() {
return implicitCascadeStyleName;
public EnumSet<CascadeType> getDefaultCascadeTypes() {
return EnumSet.noneOf( CascadeType.class );
}
@Override
public String getImplicitPropertyAccessorName() {
public jakarta.persistence.AccessType getDefaultPropertyAccessType() {
return implicitPropertyAccessType;
}
@Override
public String getDefaultAccessStrategyName() {
return implicitPropertyAccessorName;
}
@Override
public boolean areEntitiesImplicitlyLazy() {
public boolean isDefaultEntityLaziness() {
return entitiesImplicitlyLazy;
}
@Override
public boolean areCollectionsImplicitlyLazy() {
public boolean isDefaultCollectionLaziness() {
return pluralAttributesImplicitlyLazy;
}
@Override
public AccessType getImplicitCacheAccessType() {
public AccessType getDefaultCacheAccessType() {
return implicitCacheAccessType;
}
@Override
public CollectionClassification getImplicitListClassification() {
public CollectionClassification getDefaultListClassification() {
return implicitListClassification;
}
@ -143,27 +152,27 @@ public class OverriddenMappingDefaults implements MappingDefaults {
private String implicitPackageName;
private boolean autoImportEnabled;
private String implicitCascadeStyleName;
private jakarta.persistence.AccessType implicitPropertyAccessType;
private String implicitPropertyAccessorName;
private boolean entitiesImplicitlyLazy;
private boolean pluralAttributesImplicitlyLazy;
private AccessType implicitCacheAccessType;
private CollectionClassification implicitListClassification;
public Builder(MappingDefaults parentDefaults) {
this.implicitSchemaName = parentDefaults.getImplicitSchemaName();
this.implicitCatalogName = parentDefaults.getImplicitCatalogName();
this.implicitlyQuoteIdentifiers = parentDefaults.shouldImplicitlyQuoteIdentifiers();
this.implicitIdColumnName = parentDefaults.getImplicitIdColumnName();
this.implicitTenantIdColumnName = parentDefaults.getImplicitTenantIdColumnName();
this.implicitDiscriminatorColumnName = parentDefaults.getImplicitDiscriminatorColumnName();
this.implicitPackageName = parentDefaults.getImplicitPackageName();
this.autoImportEnabled = parentDefaults.isAutoImportEnabled();
this.implicitCascadeStyleName = parentDefaults.getImplicitCascadeStyleName();
this.implicitPropertyAccessorName = parentDefaults.getImplicitPropertyAccessorName();
this.entitiesImplicitlyLazy = parentDefaults.areEntitiesImplicitlyLazy();
this.pluralAttributesImplicitlyLazy = parentDefaults.areCollectionsImplicitlyLazy();
this.implicitCacheAccessType = parentDefaults.getImplicitCacheAccessType();
this.implicitListClassification = parentDefaults.getImplicitListClassification();
public Builder(EffectiveMappingDefaults parentDefaults) {
this.implicitSchemaName = parentDefaults.getDefaultSchemaName();
this.implicitCatalogName = parentDefaults.getDefaultCatalogName();
this.implicitlyQuoteIdentifiers = parentDefaults.isDefaultQuoteIdentifiers();
this.implicitIdColumnName = parentDefaults.getDefaultIdColumnName();
this.implicitTenantIdColumnName = parentDefaults.getDefaultTenantIdColumnName();
this.implicitDiscriminatorColumnName = parentDefaults.getDefaultDiscriminatorColumnName();
this.implicitPackageName = parentDefaults.getDefaultPackageName();
this.autoImportEnabled = parentDefaults.isDefaultAutoImport();
this.implicitCascadeStyleName = "none";
this.implicitPropertyAccessorName = parentDefaults.getDefaultAccessStrategyName();
this.entitiesImplicitlyLazy = parentDefaults.isDefaultEntityLaziness();
this.pluralAttributesImplicitlyLazy = parentDefaults.isDefaultCollectionLaziness();
this.implicitCacheAccessType = parentDefaults.getDefaultCacheAccessType();
}
public Builder setImplicitSchemaName(String implicitSchemaName) {
@ -225,6 +234,13 @@ public class OverriddenMappingDefaults implements MappingDefaults {
return this;
}
public Builder setImplicitPropertyAccessType(jakarta.persistence.AccessType accessType) {
if ( accessType != null ) {
this.implicitPropertyAccessType = accessType;
}
return this;
}
public Builder setImplicitPropertyAccessorName(String implicitPropertyAccessorName) {
if ( StringHelper.isNotEmpty( implicitPropertyAccessorName ) ) {
this.implicitPropertyAccessorName = implicitPropertyAccessorName;
@ -271,6 +287,7 @@ public class OverriddenMappingDefaults implements MappingDefaults {
implicitPackageName,
autoImportEnabled,
implicitCascadeStyleName,
implicitPropertyAccessType,
implicitPropertyAccessorName,
entitiesImplicitlyLazy,
pluralAttributesImplicitlyLazy,

View File

@ -7,7 +7,6 @@
package org.hibernate.boot.model.source.internal.annotations;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -28,26 +27,16 @@ import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
import org.hibernate.boot.models.categorize.spi.FilterDefRegistration;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.JpaOrmXmlPersistenceUnitDefaultAware;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.usertype.UserType;
import org.jboss.logging.Logger;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Entity;
import jakarta.persistence.MappedSuperclass;
import static org.hibernate.boot.jaxb.SourceType.OTHER;
import static org.hibernate.boot.model.internal.AnnotationHelper.resolveAttributeConverter;
import static org.hibernate.boot.model.internal.AnnotationHelper.resolveBasicType;
import static org.hibernate.boot.model.internal.AnnotationHelper.resolveJavaType;
import static org.hibernate.boot.model.internal.AnnotationHelper.resolveUserType;
import static org.hibernate.models.spi.ClassDetails.VOID_CLASS_DETAILS;
import static org.hibernate.models.spi.ClassDetails.VOID_OBJECT_CLASS_DETAILS;
@ -127,7 +116,8 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
public static void processAdditionalMappings(
List<Class<?>> additionalClasses,
List<JaxbEntityMappingsImpl> additionalJaxbMappings,
MetadataBuildingContextRootImpl rootMetadataBuildingContext) {
MetadataBuildingContextRootImpl rootMetadataBuildingContext,
MetadataBuildingOptions options) {
final AdditionalManagedResourcesImpl.Builder mrBuilder = new AdditionalManagedResourcesImpl.Builder();
mrBuilder.addLoadedClasses( additionalClasses );
for ( JaxbEntityMappingsImpl additionalJaxbMapping : additionalJaxbMappings ) {
@ -138,7 +128,8 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
final DomainModelSource additionalDomainModelSource = MetadataBuildingProcess.processManagedResources(
mr,
rootMetadataBuildingContext.getMetadataCollector(),
rootMetadataBuildingContext.getBootstrapContext()
rootMetadataBuildingContext.getBootstrapContext(),
options.getMappingDefaults()
);
final AnnotationMetadataSourceProcessorImpl processor = new AnnotationMetadataSourceProcessorImpl( mr, additionalDomainModelSource, rootMetadataBuildingContext );
processor.processEntityHierarchies( new LinkedHashSet<>() );

View File

@ -9,11 +9,11 @@ package org.hibernate.boot.model.source.internal.annotations;
import java.util.List;
import java.util.Set;
import org.hibernate.boot.internal.RootMappingDefaults;
import org.hibernate.boot.models.categorize.spi.ConversionRegistration;
import org.hibernate.boot.models.categorize.spi.ConverterRegistration;
import org.hibernate.boot.models.categorize.spi.GlobalRegistrations;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.jboss.jandex.IndexView;
@ -24,8 +24,9 @@ import org.jboss.jandex.IndexView;
public class DomainModelSource {
private final ClassDetailsRegistry classDetailsRegistry;
private final IndexView jandexIndex;
private final PersistenceUnitMetadata persistenceUnitMetadata;
private final GlobalRegistrations globalRegistrations;
private final RootMappingDefaults effectiveMappingDefaults;
private final PersistenceUnitMetadata persistenceUnitMetadata;
private final List<String> allKnownClassNames;
public DomainModelSource(
@ -33,12 +34,14 @@ public class DomainModelSource {
IndexView jandexIndex,
List<String> allKnownClassNames,
GlobalRegistrations globalRegistrations,
RootMappingDefaults effectiveMappingDefaults,
PersistenceUnitMetadata persistenceUnitMetadata) {
this.classDetailsRegistry = classDetailsRegistry;
this.jandexIndex = jandexIndex;
this.persistenceUnitMetadata = persistenceUnitMetadata;
this.globalRegistrations = globalRegistrations;
this.allKnownClassNames = allKnownClassNames;
this.globalRegistrations = globalRegistrations;
this.effectiveMappingDefaults = effectiveMappingDefaults;
this.persistenceUnitMetadata = persistenceUnitMetadata;
}
public ClassDetailsRegistry getClassDetailsRegistry() {
@ -49,14 +52,18 @@ public class DomainModelSource {
return jandexIndex;
}
public PersistenceUnitMetadata getPersistenceUnitMetadata() {
return persistenceUnitMetadata;
}
public GlobalRegistrations getGlobalRegistrations() {
return globalRegistrations;
}
public RootMappingDefaults getEffectiveMappingDefaults() {
return effectiveMappingDefaults;
}
public PersistenceUnitMetadata getPersistenceUnitMetadata() {
return persistenceUnitMetadata;
}
public List<ConversionRegistration> getConversionRegistrations() {
return globalRegistrations.getConverterRegistrations();
}

View File

@ -272,7 +272,7 @@ public abstract class AbstractEntitySourceImpl
@Override
public boolean isLazy() {
if ( jaxbEntityMapping.isLazy() == null ) {
return metadataBuildingContext().getMappingDefaults().areEntitiesImplicitlyLazy();
return metadataBuildingContext().getEffectiveDefaults().isDefaultEntityLaziness();
}
return jaxbEntityMapping().isLazy();
}

View File

@ -159,7 +159,7 @@ public abstract class AbstractPluralAttributeSourceImpl
this.elementSource = interpretElementType();
this.fetchCharacteristics = FetchCharacteristicsPluralAttributeImpl.interpret(
mappingDocument.getMappingDefaults(),
mappingDocument.getEffectiveDefaults(),
pluralAttributeJaxbMapping.getFetch(),
pluralAttributeJaxbMapping.getOuterJoin(),
pluralAttributeJaxbMapping.getLazy(),

View File

@ -94,7 +94,7 @@ public class CompositeIdentifierSingularAttributeSourceManyToOneImpl
this.attributeRole = container.getAttributeRoleBase().append( getName() );
this.fetchCharacteristics = FetchCharacteristicsSingularAssociationImpl.interpretManyToOne(
mappingDocument.getMappingDefaults(),
mappingDocument.getEffectiveDefaults(),
null,
null,
interpretLazy( mappingDocument, keyManyToOneElement )

View File

@ -10,7 +10,7 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFetchStyleWithSubselectEnum;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmLazyWithExtraEnum;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmOuterJoinEnum;
import org.hibernate.boot.model.source.spi.FetchCharacteristicsPluralAttribute;
import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
@ -65,9 +65,9 @@ public class FetchCharacteristicsPluralAttributeImpl implements FetchCharacteris
private Integer batchSize;
private boolean extraLazy;
public Builder(MappingDefaults mappingDefaults) {
public Builder(EffectiveMappingDefaults mappingDefaults) {
setFetchStyle( FetchStyle.SELECT );
if ( mappingDefaults.areCollectionsImplicitlyLazy() ) {
if ( mappingDefaults.isDefaultCollectionLaziness() ) {
setFetchTiming( FetchTiming.DELAYED );
}
else {
@ -104,7 +104,7 @@ public class FetchCharacteristicsPluralAttributeImpl implements FetchCharacteris
// Static builder methods
public static FetchCharacteristicsPluralAttributeImpl interpret(
MappingDefaults mappingDefaults,
EffectiveMappingDefaults mappingDefaults,
JaxbHbmFetchStyleWithSubselectEnum fetch,
JaxbHbmOuterJoinEnum outerJoin,
JaxbHbmLazyWithExtraEnum lazy,

View File

@ -11,7 +11,7 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmLazyEnum;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmLazyWithNoProxyEnum;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmOuterJoinEnum;
import org.hibernate.boot.model.source.spi.FetchCharacteristicsSingularAssociation;
import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.internal.log.DeprecationLogger;
@ -60,7 +60,7 @@ public class FetchCharacteristicsSingularAssociationImpl implements FetchCharact
private boolean unwrapProxies;
@SuppressWarnings("UnusedParameters")
public Builder(MappingDefaults mappingDefaults) {
public Builder(EffectiveMappingDefaults mappingDefaults) {
//
// todo : may need to add back a concept of DEFAULT fetch style / timing.
// one option I like is adding a fetchTiming / fetchStyle and
@ -96,7 +96,7 @@ public class FetchCharacteristicsSingularAssociationImpl implements FetchCharact
// Static builder methods
public static FetchCharacteristicsSingularAssociationImpl interpretManyToOne(
MappingDefaults mappingDefaults,
EffectiveMappingDefaults mappingDefaults,
JaxbHbmFetchStyleEnum fetchMapping,
JaxbHbmOuterJoinEnum outerJoinMapping,
JaxbHbmLazyWithNoProxyEnum lazyMapping) {
@ -155,7 +155,7 @@ public class FetchCharacteristicsSingularAssociationImpl implements FetchCharact
public static FetchCharacteristicsSingularAssociationImpl interpretManyToManyElement(
MappingDefaults mappingDefaults,
EffectiveMappingDefaults mappingDefaults,
JaxbHbmFetchStyleEnum fetchMapping,
JaxbHbmOuterJoinEnum outerJoinMapping,
JaxbHbmLazyEnum lazyMapping) {
@ -196,7 +196,7 @@ public class FetchCharacteristicsSingularAssociationImpl implements FetchCharact
}
public static FetchCharacteristicsSingularAssociationImpl interpretOneToOne(
MappingDefaults mappingDefaults,
EffectiveMappingDefaults mappingDefaults,
JaxbHbmFetchStyleEnum fetchMapping,
JaxbHbmOuterJoinEnum outerJoinMapping,
JaxbHbmLazyWithNoProxyEnum lazyMapping,

View File

@ -27,8 +27,8 @@ import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
import org.hibernate.boot.model.source.spi.ToolingHintContext;
import org.hibernate.boot.query.HbmResultSetMappingDescriptor;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.internal.util.StringHelper;
@ -47,7 +47,7 @@ public class MappingDocument implements HbmLocalMetadataBuildingContext, Metadat
private final JaxbHbmHibernateMapping documentRoot;
private final Origin origin;
private final MetadataBuildingContext rootBuildingContext;
private final MappingDefaults mappingDefaults;
private final EffectiveMappingDefaults mappingDefaults;
private final ToolingHintContext toolingHintContext;
@ -67,7 +67,7 @@ public class MappingDocument implements HbmLocalMetadataBuildingContext, Metadat
// todo : allow for a split in default-lazy for singular/plural
this.mappingDefaults = new OverriddenMappingDefaults.Builder( rootBuildingContext.getMappingDefaults() )
this.mappingDefaults = new OverriddenMappingDefaults.Builder( rootBuildingContext.getEffectiveDefaults() )
.setImplicitSchemaName( documentRoot.getSchema() )
.setImplicitCatalogName( documentRoot.getCatalog() )
.setImplicitPackageName( documentRoot.getPackage() )
@ -112,12 +112,12 @@ public class MappingDocument implements HbmLocalMetadataBuildingContext, Metadat
public String determineEntityName(String entityName, String clazz) {
return entityName != null
? entityName
: qualifyIfNeeded( clazz, mappingDefaults.getImplicitPackageName() );
: qualifyIfNeeded( clazz, mappingDefaults.getDefaultPackageName() );
}
@Override
public String qualifyClassName(String name) {
return qualifyIfNeeded( name, mappingDefaults.getImplicitPackageName() );
return qualifyIfNeeded( name, mappingDefaults.getDefaultPackageName() );
}
@Override
@ -141,7 +141,7 @@ public class MappingDocument implements HbmLocalMetadataBuildingContext, Metadat
}
@Override
public MappingDefaults getMappingDefaults() {
public EffectiveMappingDefaults getEffectiveDefaults() {
return mappingDefaults;
}

View File

@ -8,6 +8,7 @@ package org.hibernate.boot.model.source.internal.hbm;
import java.sql.Types;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ -18,6 +19,7 @@ import java.util.Properties;
import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode;
import org.hibernate.Remove;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.SourceType;
import org.hibernate.boot.MappingException;
import org.hibernate.boot.jaxb.Origin;
@ -430,7 +432,8 @@ public class ModelBinder {
entitySource.getEntityNamingSource().getEntityName()
);
if ( sourceDocument.getMappingDefaults().isAutoImportEnabled() && entitySource.getEntityNamingSource().getEntityName().indexOf( '.' ) > 0 ) {
if ( sourceDocument.getEffectiveDefaults().isDefaultAutoImport()
&& entitySource.getEntityNamingSource().getEntityName().indexOf( '.' ) > 0 ) {
sourceDocument.getMetadataCollector().addImport(
StringHelper.unqualify( entitySource.getEntityNamingSource().getEntityName() ),
entitySource.getEntityNamingSource().getEntityName()
@ -2447,7 +2450,7 @@ public class ModelBinder {
property.setPropertyAccessorName(
isNotEmpty( propertySource.getPropertyAccessorName() )
? propertySource.getPropertyAccessorName()
: mappingDocument.getMappingDefaults().getImplicitPropertyAccessorName()
: mappingDocument.getEffectiveDefaults().getDefaultAccessStrategyName()
);
if ( propertySource instanceof CascadeStyleSource ) {
@ -2456,7 +2459,7 @@ public class ModelBinder {
property.setCascade(
isNotEmpty( cascadeStyleSource.getCascadeStyleName() )
? cascadeStyleSource.getCascadeStyleName()
: mappingDocument.getMappingDefaults().getImplicitCascadeStyleName()
: toCascadeString( mappingDocument.getEffectiveDefaults().getDefaultCascadeTypes() )
);
}
@ -2481,6 +2484,25 @@ public class ModelBinder {
}
}
private String toCascadeString(EnumSet<CascadeType> defaultCascadeTypes) {
if ( CollectionHelper.isEmpty( defaultCascadeTypes ) ) {
return "none";
}
boolean firstPass = true;
final StringBuilder buffer = new StringBuilder();
for ( CascadeType cascadeType : defaultCascadeTypes ) {
if ( firstPass ) {
firstPass = false;
}
else {
buffer.append( ", " );
}
buffer.append( cascadeType.name().toLowerCase( Locale.ROOT ) );
}
return buffer.toString();
}
private static void handleGenerationTiming(
MappingDocument mappingDocument,
AttributeSource propertySource,
@ -3158,7 +3180,7 @@ public class ModelBinder {
if ( isNotEmpty( tableSource.getExplicitTableName() ) ) {
logicalName = toIdentifier(
tableSource.getExplicitTableName(),
mappingDocument.getMappingDefaults().shouldImplicitlyQuoteIdentifiers()
mappingDocument.getEffectiveDefaults().isDefaultQuoteIdentifiers()
);
}
else {

View File

@ -46,7 +46,7 @@ public class PluralAttributeElementSourceManyToManyImpl
: mappingDocument.qualifyClassName( jaxbManyToManyElement.getClazz() );
this.fetchCharacteristics = FetchCharacteristicsSingularAssociationImpl.interpretManyToManyElement(
mappingDocument.getMappingDefaults(),
mappingDocument.getEffectiveDefaults(),
jaxbManyToManyElement.getFetch(),
jaxbManyToManyElement.getOuterJoin(),
jaxbManyToManyElement.getLazy()

View File

@ -76,7 +76,7 @@ class SingularAttributeSourceManyToOneImpl
this.attributePath = container.getAttributePathBase().append( manyToOneElement.getName() );
this.fetchCharacteristics = FetchCharacteristicsSingularAssociationImpl.interpretManyToOne(
mappingDocument.getMappingDefaults(),
mappingDocument.getEffectiveDefaults(),
manyToOneElement.getFetch(),
manyToOneElement.getOuterJoin(),
manyToOneElement.getLazy()

View File

@ -89,7 +89,7 @@ class SingularAttributeSourceOneToOneImpl
this.attributePath = container.getAttributePathBase().append( oneToOneElement.getName() );
this.fetchCharacteristics = FetchCharacteristicsSingularAssociationImpl.interpretOneToOne(
mappingDocument.getMappingDefaults(),
mappingDocument.getEffectiveDefaults(),
oneToOneElement.getFetch(),
oneToOneElement.getOuterJoin(),
oneToOneElement.getLazy(),

View File

@ -27,7 +27,7 @@ public class BindingOptionsImpl implements BindingOptions {
private final EnumSet<QuotedIdentifierTarget> globallyQuotedIdentifierTargets;
public BindingOptionsImpl(MetadataBuildingContext metadataBuildingContext) {
final boolean globallyQuote = metadataBuildingContext.getMappingDefaults().shouldImplicitlyQuoteIdentifiers();
final boolean globallyQuote = metadataBuildingContext.getEffectiveDefaults().isDefaultQuoteIdentifiers();
final boolean skipColumnDefinitions = metadataBuildingContext
.getBootstrapContext()
.getServiceRegistry()
@ -53,13 +53,13 @@ public class BindingOptionsImpl implements BindingOptions {
.getJdbcEnvironment();
defaultCatalogName = toIdentifier(
metadataBuildingContext.getMappingDefaults().getImplicitCatalogName(),
metadataBuildingContext.getEffectiveDefaults().getDefaultCatalogName(),
QuotedIdentifierTarget.CATALOG_NAME,
globallyQuotedIdentifierTargets,
jdbcEnvironment
);
defaultSchemaName = toIdentifier(
metadataBuildingContext.getMappingDefaults().getImplicitSchemaName(),
metadataBuildingContext.getEffectiveDefaults().getDefaultSchemaName(),
QuotedIdentifierTarget.SCHEMA_NAME,
globallyQuotedIdentifierTargets,
jdbcEnvironment

View File

@ -12,7 +12,11 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.hibernate.Internal;
import org.hibernate.annotations.TenantId;
import org.hibernate.boot.internal.BootstrapContextImpl;
import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.internal.RootMappingDefaults;
import org.hibernate.boot.model.process.spi.ManagedResources;
import org.hibernate.boot.models.categorize.ModelCategorizationLogging;
import org.hibernate.boot.models.categorize.internal.ClassLoaderServiceLoading;
@ -20,6 +24,7 @@ import org.hibernate.boot.models.categorize.internal.DomainModelCategorizationCo
import org.hibernate.boot.models.categorize.internal.GlobalRegistrationsImpl;
import org.hibernate.boot.models.categorize.internal.ModelCategorizationContextImpl;
import org.hibernate.boot.models.categorize.internal.OrmAnnotationHelper;
import org.hibernate.boot.models.xml.internal.PersistenceUnitMetadataImpl;
import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult;
import org.hibernate.boot.models.xml.spi.XmlPreProcessor;
import org.hibernate.boot.models.xml.spi.XmlProcessingResult;
@ -27,6 +32,7 @@ import org.hibernate.boot.models.xml.spi.XmlProcessor;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.models.internal.SourceModelBuildingContextImpl;
import org.hibernate.models.internal.jandex.JandexClassDetails;
import org.hibernate.models.internal.jandex.JandexIndexerHelper;
@ -55,6 +61,7 @@ import static org.hibernate.internal.util.collections.CollectionHelper.mutableJo
public class ManagedResourcesProcessor {
public static CategorizedDomainModel processManagedResources(
ManagedResources managedResources,
MetadataBuildingOptions metadataBuildingOptions,
BootstrapContext bootstrapContext) {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -76,7 +83,12 @@ public class ManagedResourcesProcessor {
final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class );
final ClassLoaderServiceLoading classLoading = new ClassLoaderServiceLoading( classLoaderService );
final XmlPreProcessingResult xmlPreProcessingResult = XmlPreProcessor.preProcessXmlResources( managedResources );
final PersistenceUnitMetadataImpl persistenceUnitMetadata = new PersistenceUnitMetadataImpl();
final XmlPreProcessingResult xmlPreProcessingResult = XmlPreProcessor.preProcessXmlResources(
managedResources,
persistenceUnitMetadata
);
//noinspection unchecked
final List<String> allKnownClassNames = mutableJoin(
@ -133,11 +145,16 @@ public class ManagedResourcesProcessor {
sourceModelBuildingContext
);
final RootMappingDefaults rootMappingDefaults = new RootMappingDefaults(
metadataBuildingOptions.getMappingDefaults(),
persistenceUnitMetadata
);
final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml(
xmlPreProcessingResult,
modelCategorizationCollector,
sourceModelBuildingContext,
bootstrapContext
bootstrapContext,
rootMappingDefaults
);
allKnownClassNames.forEach( (className) -> {
@ -281,4 +298,17 @@ public class ManagedResourcesProcessor {
}
}
/**
* For testing use only
*/
@Internal
public static CategorizedDomainModel processManagedResources(
ManagedResources managedResources,
BootstrapContext bootstrapContext) {
return processManagedResources(
managedResources,
new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ),
bootstrapContext
);
}
}

View File

@ -124,7 +124,7 @@ public class ManagedTypeProcessor {
classAccessType = coalesce(
jaxbEntity.getAccess(),
jaxbRoot.getAccess(),
xmlDocumentContext.getPersistenceUnitMetadata().getAccessType(),
xmlDocumentContext.getEffectiveDefaults().getDefaultPropertyAccessType(),
AccessType.PROPERTY
);
}
@ -653,7 +653,7 @@ public class ManagedTypeProcessor {
// look for @Access on the entity class
() -> determineAccessTypeFromClassAnnotations( classDetails ),
// look for a default (PU metadata default) access
xmlDocumentContext.getPersistenceUnitMetadata()::getAccessType,
xmlDocumentContext.getEffectiveDefaults()::getDefaultPropertyAccessType,
// look at @Id/@EmbeddedId
() -> determineAccessTypeFromClassMembers( classDetails ),
// fallback to PROPERTY
@ -781,7 +781,7 @@ public class ManagedTypeProcessor {
final AccessType classAccessType = coalesce(
jaxbMappedSuperclass.getAccess(),
xmlDocumentContext.getPersistenceUnitMetadata().getAccessType()
xmlDocumentContext.getEffectiveDefaults().getDefaultPropertyAccessType()
);
classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation( classAccessType, classDetails, xmlDocumentContext ) );
@ -862,7 +862,7 @@ public class ManagedTypeProcessor {
classDetails = (MutableClassDetails) classDetailsRegistry.resolveClassDetails( className );
classAccessType = coalesce(
jaxbEmbeddable.getAccess(),
xmlDocumentContext.getPersistenceUnitMetadata().getAccessType()
xmlDocumentContext.getEffectiveDefaults().getDefaultPropertyAccessType()
);
memberAdjuster = ManagedTypeProcessor::adjustNonDynamicTypeMember;
}

View File

@ -37,6 +37,9 @@ public final class PersistenceUnitMetadataImpl implements PersistenceUnitMetadat
private final EnumSet<CascadeType> defaultCascadeTypes = EnumSet.noneOf( CascadeType.class );
public PersistenceUnitMetadataImpl() {
}
@Override
public boolean areXmlMappingsComplete() {
return xmlComplete;
@ -132,7 +135,7 @@ public final class PersistenceUnitMetadataImpl implements PersistenceUnitMetadat
if ( defaults.getCascadePersist() != null
|| isNotEmpty( defaults.getDefaultCascade() ) ) {
if ( !defaultCascadeTypes.isEmpty() ) {
if ( !this.defaultCascadeTypes.isEmpty() ) {
XML_PROCESS_LOGGER.debugf( "Adding cascades to already defined set of default cascades" );
}

View File

@ -544,8 +544,8 @@ public class XmlAnnotationHelper {
return;
}
// We always use Hibernate specific org.hibernate.annotations.CascadeType since
// it offers additional options than jakarta.persistence.CascadeType
// We always use Hibernate specific `org.hibernate.annotations.CascadeType`
// since it is a superset of `jakarta.persistence.CascadeType`
final List<CascadeType> cascadeTypes = new ArrayList<>();
if ( jaxbCascadeType.getCascadeAll() != null ) {
cascadeTypes.add( CascadeType.ALL );

View File

@ -6,10 +6,14 @@
*/
package org.hibernate.boot.models.xml.internal;
import org.hibernate.boot.internal.RootMappingDefaults;
import org.hibernate.boot.model.source.internal.OverriddenMappingDefaults;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.boot.models.xml.spi.XmlDocument;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.models.spi.SourceModelBuildingContext;
/**
@ -17,17 +21,17 @@ import org.hibernate.models.spi.SourceModelBuildingContext;
*/
public class XmlDocumentContextImpl implements XmlDocumentContext {
private final XmlDocument xmlDocument;
private final PersistenceUnitMetadata persistenceUnitMetadata;
private final EffectiveMappingDefaults effectiveDefaults;
private final SourceModelBuildingContext modelBuildingContext;
private final BootstrapContext bootstrapContext;
public XmlDocumentContextImpl(
XmlDocument xmlDocument,
PersistenceUnitMetadata persistenceUnitMetadata,
RootMappingDefaults mappingDefaults,
SourceModelBuildingContext modelBuildingContext,
BootstrapContext bootstrapContext) {
this.xmlDocument = xmlDocument;
this.persistenceUnitMetadata = persistenceUnitMetadata;
this.effectiveDefaults = buildEffectiveDefaults( xmlDocument, mappingDefaults );
this.modelBuildingContext = modelBuildingContext;
this.bootstrapContext = bootstrapContext;
}
@ -38,8 +42,8 @@ public class XmlDocumentContextImpl implements XmlDocumentContext {
}
@Override
public PersistenceUnitMetadata getPersistenceUnitMetadata() {
return persistenceUnitMetadata;
public EffectiveMappingDefaults getEffectiveDefaults() {
return effectiveDefaults;
}
@Override
@ -51,4 +55,42 @@ public class XmlDocumentContextImpl implements XmlDocumentContext {
public BootstrapContext getBootstrapContext() {
return bootstrapContext;
}
private static EffectiveMappingDefaults buildEffectiveDefaults(
XmlDocument xmlDocument,
RootMappingDefaults mappingDefaults) {
final XmlDocument.Defaults documentDefaults = xmlDocument.getDefaults();
final OverriddenMappingDefaults.Builder builder = new OverriddenMappingDefaults.Builder( mappingDefaults );
if ( StringHelper.isNotEmpty( documentDefaults.getCatalog() ) ) {
builder.setImplicitCatalogName( documentDefaults.getCatalog() );
}
if ( StringHelper.isNotEmpty( documentDefaults.getSchema() ) ) {
builder.setImplicitSchemaName( documentDefaults.getSchema() );
}
if ( documentDefaults.isAutoImport() ) {
builder.setAutoImportEnabled( true );
}
if ( StringHelper.isNotEmpty( documentDefaults.getPackage() ) ) {
builder.setImplicitPackageName( documentDefaults.getPackage() );
}
if ( documentDefaults.getAccessType() != null ) {
builder.setImplicitPropertyAccessType( documentDefaults.getAccessType() );
}
if ( StringHelper.isNotEmpty( documentDefaults.getAccessorStrategy() ) ) {
builder.setImplicitPropertyAccessorName( documentDefaults.getAccessorStrategy() );
}
if ( documentDefaults.isLazinessImplied() ) {
builder.setEntitiesImplicitlyLazy( true );
builder.setPluralAttributesImplicitlyLazy( true );
}
return builder.build();
}
}

View File

@ -10,6 +10,7 @@ import java.util.ArrayList;
import java.util.List;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult;
import org.hibernate.internal.util.StringHelper;
@ -17,11 +18,26 @@ import org.hibernate.internal.util.StringHelper;
* @author Steve Ebersole
*/
public class XmlPreProcessingResultImpl implements XmlPreProcessingResult {
private final PersistenceUnitMetadataImpl persistenceUnitMetadata = new PersistenceUnitMetadataImpl();
private final PersistenceUnitMetadataImpl persistenceUnitMetadata;
private final List<JaxbEntityMappingsImpl> documents = new ArrayList<>();
private final List<String> managedClasses = new ArrayList<>();
private final List<String> managedNames = new ArrayList<>();
public XmlPreProcessingResultImpl(PersistenceUnitMetadataImpl persistenceUnitMetadata) {
this.persistenceUnitMetadata = persistenceUnitMetadata;
}
public XmlPreProcessingResultImpl(PersistenceUnitMetadata persistenceUnitMetadata) {
this( (PersistenceUnitMetadataImpl) persistenceUnitMetadata );
}
/**
* Intended for testing
*/
public XmlPreProcessingResultImpl() {
this( new PersistenceUnitMetadataImpl() );
}
@Override
public PersistenceUnitMetadataImpl getPersistenceUnitMetadata() {
return persistenceUnitMetadata;

View File

@ -19,6 +19,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingDiscriminatorImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingKeyImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnImpl;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.xml.internal.db.ColumnProcessing;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
@ -61,6 +62,7 @@ public class AnyMappingAttributeProcessing {
applyDiscriminator( memberDetails, jaxbHbmAnyMapping, anyAnn, xmlDocumentContext );
applyKey( memberDetails, jaxbHbmAnyMapping, anyAnn, xmlDocumentContext );
XmlAnnotationHelper.applyCascading( jaxbHbmAnyMapping.getCascade(), memberDetails, xmlDocumentContext );
return memberDetails;
}

View File

@ -48,11 +48,9 @@ public class OneToManyAttributeProcessing {
applyTargetEntity( jaxbOneToMany, oneToManyAnn, xmlDocumentContext );
XmlAnnotationHelper.applyCascading( jaxbOneToMany.getCascade(), memberDetails, xmlDocumentContext );
CommonAttributeProcessing.applyAttributeBasics( jaxbOneToMany, memberDetails, oneToManyAnn, accessType, xmlDocumentContext );
CommonPluralAttributeProcessing.applyPluralAttributeStructure( jaxbOneToMany, memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applyCascading( jaxbOneToMany.getCascade(), memberDetails, xmlDocumentContext );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// join-table

View File

@ -7,12 +7,16 @@
package org.hibernate.boot.models.xml.internal.attr;
import org.hibernate.boot.jaxb.mapping.spi.JaxbPluralAnyMappingImpl;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.models.spi.MutableClassDetails;
import org.hibernate.models.spi.MutableMemberDetails;
import jakarta.persistence.AccessType;
import static org.hibernate.internal.util.NullnessHelper.coalesce;
/**
* @author Steve Ebersole
*/
@ -21,9 +25,17 @@ public class PluralAnyMappingAttributeProcessing {
@SuppressWarnings("UnusedReturnValue")
public static MutableMemberDetails processPluralAnyMappingAttributes(
JaxbPluralAnyMappingImpl jaxbHbmManyToAny,
MutableClassDetails mutableClassDetails,
MutableClassDetails declarer,
AccessType classAccessType,
XmlDocumentContext xmlDocumentContext) {
final AccessType accessType = coalesce( jaxbHbmManyToAny.getAccess(), classAccessType );
final MutableMemberDetails memberDetails = XmlProcessingHelper.getAttributeMember(
jaxbHbmManyToAny.getName(),
accessType,
declarer
);
XmlAnnotationHelper.applyCascading( jaxbHbmManyToAny.getCascade(), memberDetails, xmlDocumentContext );
throw new UnsupportedOperationException( "Support for many-to-any attributes not yet implemented" );
}
}

View File

@ -22,6 +22,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbPluralAttribute;
import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeImpl;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.models.internal.dynamic.DynamicClassDetails;
import org.hibernate.models.spi.ClassDetails;
@ -47,10 +48,7 @@ public interface XmlDocumentContext {
*/
XmlDocument getXmlDocument();
/**
* The {@code <persistence-unit-metadata/>} defined by the XML document
*/
PersistenceUnitMetadata getPersistenceUnitMetadata();
EffectiveMappingDefaults getEffectiveDefaults();
/**
* Access to the containing SourceModelBuildingContext

View File

@ -24,8 +24,10 @@ public class XmlPreProcessor {
/**
* Build an XmlResources reference based on the given {@code managedResources}
*/
public static XmlPreProcessingResult preProcessXmlResources(ManagedResources managedResources) {
final XmlPreProcessingResultImpl collected = new XmlPreProcessingResultImpl();
public static XmlPreProcessingResult preProcessXmlResources(
ManagedResources managedResources,
PersistenceUnitMetadata persistenceUnitMetadata) {
final XmlPreProcessingResultImpl collected = new XmlPreProcessingResultImpl( persistenceUnitMetadata );
for ( Binding<JaxbBindableMappingDescriptor> mappingXmlBinding : managedResources.getXmlMappingBindings() ) {
// for now skip hbm.xml
@ -33,7 +35,8 @@ public class XmlPreProcessor {
if ( root instanceof JaxbHbmHibernateMapping ) {
continue;
}
collected.addDocument( (JaxbEntityMappingsImpl) root );
final JaxbEntityMappingsImpl jaxbEntityMappings = (JaxbEntityMappingsImpl) root;
collected.addDocument( jaxbEntityMappings );
}
return collected;

View File

@ -6,12 +6,14 @@
*/
package org.hibernate.boot.models.xml.spi;
import org.hibernate.boot.internal.RootMappingDefaults;
import org.hibernate.boot.models.categorize.internal.DomainModelCategorizationCollector;
import org.hibernate.boot.models.xml.internal.ManagedTypeProcessor;
import org.hibernate.boot.models.xml.internal.XmlDocumentContextImpl;
import org.hibernate.boot.models.xml.internal.XmlDocumentImpl;
import org.hibernate.boot.models.xml.internal.XmlProcessingResultImpl;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.models.spi.SourceModelBuildingContext;
/**
@ -25,7 +27,8 @@ public class XmlProcessor {
XmlPreProcessingResult xmlPreProcessingResult,
DomainModelCategorizationCollector modelCategorizationCollector,
SourceModelBuildingContext sourceModelBuildingContext,
BootstrapContext bootstrapContext) {
BootstrapContext bootstrapContext,
RootMappingDefaults mappingDefaults) {
final boolean xmlMappingsGloballyComplete = xmlPreProcessingResult.getPersistenceUnitMetadata().areXmlMappingsComplete();
final XmlProcessingResultImpl xmlOverlay = new XmlProcessingResultImpl();
@ -37,7 +40,7 @@ public class XmlProcessor {
);
final XmlDocumentContext xmlDocumentContext = new XmlDocumentContextImpl(
xmlDocument,
xmlPreProcessingResult.getPersistenceUnitMetadata(),
mappingDefaults,
sourceModelBuildingContext,
bootstrapContext
);

View File

@ -0,0 +1,151 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.boot.spi;
import java.util.EnumSet;
import org.hibernate.annotations.CascadeType;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.metamodel.CollectionClassification;
/**
* Defaults which are in effect for each mapping.
* A combination of global settings and XML-specific settings
*
* @see MappingDefaults
* @see PersistenceUnitMetadata
* @see JaxbEntityMappingsImpl
*
* @author Steve Ebersole
*/
public interface EffectiveMappingDefaults {
String DEFAULT_IDENTIFIER_COLUMN_NAME = "id";
String DEFAULT_TENANT_IDENTIFIER_COLUMN_NAME = "tenant_id";
String DEFAULT_DISCRIMINATOR_COLUMN_NAME = "class";
/**
* The default database catalog name to use
*
* @see MappingDefaults#getImplicitCatalogName()
* @see PersistenceUnitMetadata#getDefaultCatalog()
*/
String getDefaultCatalogName();
/**
* The default database schema name to use
*
* @see MappingDefaults#getImplicitCatalogName()
* @see PersistenceUnitMetadata#getDefaultCatalog()
*/
String getDefaultSchemaName();
/**
* Whether database identifiers be quoted by default
*
* @see MappingDefaults#shouldImplicitlyQuoteIdentifiers()
* @see PersistenceUnitMetadata#useQuotedIdentifiers()
*
*/
boolean isDefaultQuoteIdentifiers();
/**
* The default column name to use for the identifier column if none specified in
* the mapping.
* Falls back to {@value #DEFAULT_IDENTIFIER_COLUMN_NAME}.
*/
String getDefaultIdColumnName();
/**
* The default column name to use for the discriminator column if none specified
* in the mapping.
* Falls back to {@value #DEFAULT_DISCRIMINATOR_COLUMN_NAME}.
*/
String getDefaultDiscriminatorColumnName();
/**
* The default column name to use for the tenant identifier column if none is
* specified in the mapping.
* Falls back to {@value #DEFAULT_TENANT_IDENTIFIER_COLUMN_NAME}.
*/
String getDefaultTenantIdColumnName();
/**
* The default package name to use if none specified in XML mappings.
* Useful when all (or most) domain classes are in a single package.
*
* @see MappingDefaults#getImplicitPackageName()
* @see JaxbEntityMappingsImpl#getPackage()
*/
String getDefaultPackageName();
/**
* Whether auto-importing of entity names (for queries) is enabled.
*
* @see MappingDefaults#isAutoImportEnabled()
* @see JaxbEntityMappingsImpl#isAutoImport()
*/
boolean isDefaultAutoImport();
/**
* The default cascade styles to apply to associations.
*
* @see MappingDefaults#getImplicitCascadeStyleName()
* @see PersistenceUnitMetadata#getDefaultCascadeTypes()
* @see JaxbEntityMappingsImpl#getDefaultCascade()
*/
EnumSet<CascadeType> getDefaultCascadeTypes();
/**
* The default AccessType to use if not specified in the mapping.
*
* @see PersistenceUnitMetadata#getAccessType()
*/
jakarta.persistence.AccessType getDefaultPropertyAccessType();
/**
* The default {@link org.hibernate.property.access.spi.PropertyAccessStrategy} name to use if
* none specified in the mapping.
*
* @see #getDefaultPropertyAccessType
* @see MappingDefaults#getImplicitPropertyAccessorName()
* @see JaxbEntityMappingsImpl#getAttributeAccessor()
*/
String getDefaultAccessStrategyName();
/**
* Whether singular associations (many-to-one, one-to-one) are lazy by default if not specified in the mapping.
*
* @see MappingDefaults#areEntitiesImplicitlyLazy()
* @see JaxbEntityMappingsImpl#isDefaultLazy()
*/
boolean isDefaultEntityLaziness();
/**
* Whether plural attributes are lazy by default if not specified in the mapping.
*
* @see MappingDefaults#areCollectionsImplicitlyLazy() ()
* @see JaxbEntityMappingsImpl#isDefaultLazy()
*/
boolean isDefaultCollectionLaziness();
/**
* The default cache access strategy to use if none is specified
*
* @see MappingDefaults#getImplicitCacheAccessType()
*/
AccessType getDefaultCacheAccessType();
/**
* @deprecated No longer supported
*/
@Deprecated
default CollectionClassification getDefaultListClassification() {
return CollectionClassification.LIST;
}
}

View File

@ -31,6 +31,8 @@ public interface MappingDefaults {
* Identifies the database schema name to use if none specified in the mapping.
*
* @return The implicit schema name; may be {@code null}
*
* @see org.hibernate.cfg.MappingSettings#DEFAULT_SCHEMA
*/
String getImplicitSchemaName();
@ -38,6 +40,8 @@ public interface MappingDefaults {
* Identifies the database catalog name to use if none specified in the mapping.
*
* @return The implicit catalog name; may be {@code null}
*
* @see org.hibernate.cfg.MappingSettings#DEFAULT_CATALOG
*/
String getImplicitCatalogName();
@ -99,10 +103,7 @@ public interface MappingDefaults {
String getImplicitCascadeStyleName();
/**
* Identifies the default {@link org.hibernate.property.access.spi.PropertyAccessStrategy} name to use if none specified in the
* mapping.
*
* @return The implicit property accessor name
* The default {@link org.hibernate.property.access.spi.PropertyAccessStrategy} to use if none specified in the mapping.
*
* @see org.hibernate.property.access.spi.PropertyAccessStrategy
*/

View File

@ -39,7 +39,7 @@ public interface MetadataBuildingContext {
*
* @return The mapping defaults.
*/
MappingDefaults getMappingDefaults();
EffectiveMappingDefaults getEffectiveDefaults();
/**
* Access to the collector of metadata as we build it.

View File

@ -13,6 +13,7 @@ import org.hibernate.boot.internal.BootstrapContextImpl;
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
import org.hibernate.boot.internal.RootMappingDefaults;
import org.hibernate.boot.model.process.spi.ManagedResources;
import org.hibernate.boot.model.process.spi.MetadataBuildingProcess;
import org.hibernate.boot.models.bind.internal.BindingContextImpl;
@ -54,11 +55,17 @@ public class BindingTestingHelper {
bootstrapContext
);
final RootMappingDefaults mappingDefaults = new RootMappingDefaults(
new MetadataBuilderImpl.MappingDefaultsImpl( serviceRegistry ),
metadataCollector.getPersistenceUnitMetadata()
);
final MetadataBuildingContextRootImpl metadataBuildingContext = new MetadataBuildingContextRootImpl(
"models",
bootstrapContext,
bootstrapContext.getMetadataBuildingOptions(),
metadataCollector
metadataCollector,
mappingDefaults
);
final BindingStateImpl bindingState = new BindingStateImpl( metadataBuildingContext );
final BindingOptionsImpl bindingOptions = new BindingOptionsImpl( metadataBuildingContext );

View File

@ -11,6 +11,7 @@ import java.util.List;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.internal.BootstrapContextImpl;
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl;
import org.hibernate.boot.model.process.spi.ManagedResources;
import org.hibernate.boot.model.process.spi.MetadataBuildingProcess;
@ -53,7 +54,8 @@ public class AttributeOverrideXmlTests {
final DomainModelSource domainModelSource = processManagedResources(
managedResources,
metadataCollector,
bootstrapContext
bootstrapContext,
new MetadataBuilderImpl.MappingDefaultsImpl( registry )
);
final ClassDetailsRegistry classDetailsRegistry = domainModelSource.getClassDetailsRegistry();

View File

@ -6,8 +6,10 @@
*/
package org.hibernate.orm.test.jpa.mapping;
import java.util.Arrays;
import java.util.List;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@ -15,15 +17,6 @@ import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
/**
* @author Vlad Mihalcea
*/
@ -32,12 +25,7 @@ import org.junit.jupiter.api.Test;
DefaultCascadeTest.Parent.class,
DefaultCascadeTest.Child.class
},
// using 'xmlMappings = { "org/hibernate/orm/test/jpa/mapping/orm.xml" }' also works
settingProviders = {
@SettingProvider(
settingName = AvailableSettings.ORM_XML_FILES,
provider = DefaultCascadeTest.EJB3DDMappingProvider.class )
}
xmlMappings = "org/hibernate/orm/test/jpa/mapping/orm.xml"
)
public class DefaultCascadeTest {
@ -85,10 +73,4 @@ public class DefaultCascadeTest {
private Parent parent;
}
public static class EJB3DDMappingProvider implements SettingProvider.Provider<List<String>> {
@Override
public List<String> getSetting() {
return Arrays.asList( "org/hibernate/orm/test/jpa/mapping/orm.xml" );
}
}
}

View File

@ -64,7 +64,7 @@ public class EnversMetadataBuildingContextImpl implements EnversMetadataBuilding
}
@Override
public MappingDefaults getMappingDefaults() {
public MappingDefaults getEffectiveDefaults() {
return metadataCollector.getMetadataBuildingOptions().getMappingDefaults();
}

View File

@ -9,10 +9,13 @@ package org.hibernate.testing.boot;
import org.hibernate.boot.internal.BootstrapContextImpl;
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.internal.RootMappingDefaults;
import org.hibernate.boot.model.TypeDefinitionRegistryStandardImpl;
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
import org.hibernate.boot.models.xml.internal.PersistenceUnitMetadataImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuildingContext;
@ -23,7 +26,7 @@ import org.hibernate.boot.spi.MetadataBuildingOptions;
*/
public class MetadataBuildingContextTestingImpl implements MetadataBuildingContext {
private final MetadataBuildingOptions buildingOptions;
private final MappingDefaults mappingDefaults;
private final EffectiveMappingDefaults mappingDefaults;
private final InFlightMetadataCollector metadataCollector;
private final BootstrapContext bootstrapContext;
private final ObjectNameNormalizer objectNameNormalizer;
@ -33,7 +36,10 @@ public class MetadataBuildingContextTestingImpl implements MetadataBuildingConte
MetadataBuilderImpl.MetadataBuildingOptionsImpl buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry );
this.buildingOptions = buildingOptions;
buildingOptions.setBootstrapContext( bootstrapContext = new BootstrapContextImpl( serviceRegistry, buildingOptions ) );
mappingDefaults = new MetadataBuilderImpl.MappingDefaultsImpl( serviceRegistry );
mappingDefaults = new RootMappingDefaults(
new MetadataBuilderImpl.MappingDefaultsImpl( serviceRegistry ),
new PersistenceUnitMetadataImpl()
);
metadataCollector = new InFlightMetadataCollectorImpl( bootstrapContext, buildingOptions );
objectNameNormalizer = new ObjectNameNormalizer() {
@Override
@ -56,7 +62,7 @@ public class MetadataBuildingContextTestingImpl implements MetadataBuildingConte
}
@Override
public MappingDefaults getMappingDefaults() {
public EffectiveMappingDefaults getEffectiveDefaults() {
return mappingDefaults;
}

View File

@ -27,6 +27,7 @@ import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
@ -783,6 +784,11 @@ public abstract class MockSessionFactory
return new MockMappingDefaults();
}
@Override
public EffectiveMappingDefaults getEffectiveDefaults() {
throw new UnsupportedOperationException();
}
@Override
public TimeZoneStorageStrategy getDefaultTimeZoneStorageStrategy() {
return TimeZoneStorageStrategy.NATIVE;