Skip to content

HHH-19317 - Mark org.hibernate.boot.models as incubating #9960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.hibernate.boot.model.source.internal.hbm.ModelBinder;
import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
import org.hibernate.boot.models.internal.DomainModelCategorizationCollector;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult;
import org.hibernate.boot.models.xml.spi.XmlPreProcessor;
import org.hibernate.boot.models.xml.spi.XmlProcessingResult;
Expand Down Expand Up @@ -373,14 +374,13 @@ public static DomainModelSource processManagedResources(
// - allKnownClassNames (technically could be included in xmlPreProcessingResult)
// - sourceModelBuildingContext

final PersistenceUnitMetadata aggregatedPersistenceUnitMetadata = metadataCollector.getPersistenceUnitMetadata();
final SourceModelBuildingContext modelsContext = bootstrapContext.getModelsContext();
final XmlPreProcessingResult xmlPreProcessingResult = XmlPreProcessor.preProcessXmlResources(
managedResources,
metadataCollector.getPersistenceUnitMetadata()
aggregatedPersistenceUnitMetadata
);

assert metadataCollector.getPersistenceUnitMetadata() == xmlPreProcessingResult.getPersistenceUnitMetadata();

final List<String> allKnownClassNames = mutableJoin(
managedResources.getAnnotatedClassReferences().stream().map( Class::getName ).collect( Collectors.toList() ),
managedResources.getAnnotatedClassNames(),
Expand Down Expand Up @@ -413,22 +413,20 @@ public static DomainModelSource processManagedResources(
// - mappedSuperClasses
// - embeddables

// JPA id generator global-ity thing
final boolean areIdGeneratorsGlobal = true;
final ClassDetailsRegistry classDetailsRegistry = modelsContext.getClassDetailsRegistry();
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
areIdGeneratorsGlobal,
metadataCollector.getGlobalRegistrations(),
modelsContext
);

final RootMappingDefaults rootMappingDefaults = new RootMappingDefaults(
optionDefaults,
xmlPreProcessingResult.getPersistenceUnitMetadata()
aggregatedPersistenceUnitMetadata
);
final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml(
xmlPreProcessingResult,
modelCategorizationCollector,
aggregatedPersistenceUnitMetadata,
modelCategorizationCollector::apply,
modelsContext,
bootstrapContext,
rootMappingDefaults
Expand All @@ -448,14 +446,14 @@ public static DomainModelSource processManagedResources(
modelCategorizationCollector
) );

xmlProcessingResult.apply( xmlPreProcessingResult.getPersistenceUnitMetadata() );
xmlProcessingResult.apply();

return new DomainModelSource(
classDetailsRegistry,
allKnownClassNames,
modelCategorizationCollector.getGlobalRegistrations(),
rootMappingDefaults,
xmlPreProcessingResult.getPersistenceUnitMetadata()
aggregatedPersistenceUnitMetadata
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public Builder(EffectiveMappingDefaults parentDefaults) {
this.autoImportEnabled = parentDefaults.isDefaultAutoImport();

this.implicitCascadeTypes = parentDefaults.getDefaultCascadeTypes();
this.implicitPropertyAccessType = parentDefaults.getDefaultPropertyAccessType();
this.implicitPropertyAccessorName = parentDefaults.getDefaultAccessStrategyName();
this.entitiesImplicitlyLazy = parentDefaults.isDefaultEntityLaziness();
this.pluralAttributesImplicitlyLazy = parentDefaults.isDefaultCollectionLaziness();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
* @author Steve Ebersole
*/
public class DomainModelCategorizationCollector {
private final boolean areIdGeneratorsGlobal;

private final GlobalRegistrationsImpl globalRegistrations;
private final SourceModelBuildingContext modelsContext;

Expand All @@ -39,10 +37,8 @@ public class DomainModelCategorizationCollector {
private final Map<String,ClassDetails> embeddables = new HashMap<>();

public DomainModelCategorizationCollector(
boolean areIdGeneratorsGlobal,
GlobalRegistrations globalRegistrations,
SourceModelBuildingContext modelsContext) {
this.areIdGeneratorsGlobal = areIdGeneratorsGlobal;
this.globalRegistrations = (GlobalRegistrationsImpl) globalRegistrations;
this.modelsContext = modelsContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* building the {@code hibernate-models} model ({@linkplain org.hibernate.models.spi.ClassDetails}, etc.)
* to ultimately be bound into Hibernate's {@linkplain org.hibernate.mapping boot-time model}.
*
* @apiNote This entire package is considered incubating
*
* @author Steve Ebersole
*/
@Incubating
package org.hibernate.boot.models;

import org.hibernate.Incubating;
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
* @see JaxbEntityListenerImpl
* @see GlobalRegistrations#getEntityListenerRegistrations()
*
* @see jakarta.persistence.PostLoad
* @see jakarta.persistence.PostPersist
* @see jakarta.persistence.PostRemove
* @see jakarta.persistence.PostUpdate
* @see jakarta.persistence.PrePersist
* @see jakarta.persistence.PreRemove
* @see jakarta.persistence.PreUpdate
*
* @author Steve Ebersole
*/
public class JpaEventListener {
Expand All @@ -59,7 +67,7 @@ public class JpaEventListener {

private final MethodDetails postLoadMethod;

private JpaEventListener(
public JpaEventListener(
JpaEventListenerStyle consumerType,
ClassDetails listenerClass,
MethodDetails prePersistMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
*/
package org.hibernate.boot.models.xml.internal;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jakarta.persistence.AccessType;
import org.hibernate.boot.jaxb.Origin;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedNativeQueryType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedQueryType;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCollectionUserTypeRegistrationImpl;
Expand All @@ -22,22 +19,28 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbJavaTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbJdbcTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclassImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeRegistrationImpl;
import org.hibernate.boot.jaxb.spi.Binding;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.boot.models.xml.spi.XmlDocument;
import org.hibernate.internal.util.NullnessHelper;

import jakarta.persistence.AccessType;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;

/**
* @author Steve Ebersole
*/
public class XmlDocumentImpl implements XmlDocument {
private final Origin origin;
private final JaxbEntityMappingsImpl root;
private final DefaultsImpl defaults;
private final List<JaxbEntityImpl> entityMappings;
private final List<JaxbMappedSuperclassImpl> mappedSuperclassMappings;
Expand All @@ -57,6 +60,8 @@ public class XmlDocumentImpl implements XmlDocument {
private final Map<String, JaxbNamedStoredProcedureQueryImpl> namedStoredProcedureQueries;

private XmlDocumentImpl(
Origin origin,
JaxbEntityMappingsImpl root,
DefaultsImpl defaults,
List<JaxbEntityImpl> entityMappings,
List<JaxbMappedSuperclassImpl> mappedSuperclassMappings,
Expand All @@ -74,6 +79,8 @@ private XmlDocumentImpl(
Map<String, JaxbNamedStoredProcedureQueryImpl> namedStoredProcedureQueries,
Map<String, JaxbHbmNamedQueryType> hibernateNamedQueries,
Map<String, JaxbHbmNamedNativeQueryType> hibernateNamedNativeQueries) {
this.origin = origin;
this.root = root;
this.defaults = defaults;
this.entityMappings = entityMappings;
this.mappedSuperclassMappings = mappedSuperclassMappings;
Expand All @@ -93,6 +100,16 @@ private XmlDocumentImpl(
this.hibernateNamedNativeQueries = hibernateNamedNativeQueries;
}

@Override
public Origin getOrigin() {
return origin;
}

@Override
public JaxbEntityMappingsImpl getRoot() {
return root;
}

@Override
public Defaults getDefaults() {
return defaults;
Expand Down Expand Up @@ -252,8 +269,11 @@ static DefaultsImpl consume(JaxbEntityMappingsImpl jaxbRoot, PersistenceUnitMeta
}
}

public static XmlDocumentImpl consume(JaxbEntityMappingsImpl jaxbRoot, PersistenceUnitMetadata metadata) {
public static XmlDocumentImpl consume(Binding<JaxbEntityMappingsImpl> xmlBinding, PersistenceUnitMetadata metadata) {
final JaxbEntityMappingsImpl jaxbRoot = xmlBinding.getRoot();
return new XmlDocumentImpl(
xmlBinding.getOrigin(),
xmlBinding.getRoot(),
DefaultsImpl.consume( jaxbRoot, metadata ),
jaxbRoot.getEntities(),
jaxbRoot.getMappedSuperclasses(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.util.List;

import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
import org.hibernate.boot.jaxb.spi.Binding;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.boot.models.xml.spi.XmlDocument;
import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult;
import org.hibernate.internal.util.StringHelper;

Expand All @@ -17,7 +19,7 @@
*/
public class XmlPreProcessingResultImpl implements XmlPreProcessingResult {
private final PersistenceUnitMetadataImpl persistenceUnitMetadata;
private final List<JaxbEntityMappingsImpl> documents = new ArrayList<>();
private final List<XmlDocument> documents = new ArrayList<>();
private final List<String> managedClasses = new ArrayList<>();
private final List<String> managedNames = new ArrayList<>();

Expand All @@ -36,13 +38,12 @@ public XmlPreProcessingResultImpl() {
this( new PersistenceUnitMetadataImpl() );
}

@Override
public PersistenceUnitMetadataImpl getPersistenceUnitMetadata() {
return persistenceUnitMetadata;
}

@Override
public List<JaxbEntityMappingsImpl> getDocuments() {
public List<XmlDocument> getDocuments() {
return documents;
}

Expand All @@ -56,23 +57,26 @@ public List<String> getMappedNames() {
return managedNames;
}

public void addDocument(JaxbEntityMappingsImpl document) {
persistenceUnitMetadata.apply( document.getPersistenceUnitMetadata() );
documents.add( document );
document.getEmbeddables().forEach( (jaxbEmbeddable) -> {
public void addDocument(Binding<JaxbEntityMappingsImpl> binding) {
final XmlDocumentImpl xmlDocument = XmlDocumentImpl.consume( binding, persistenceUnitMetadata );
documents.add( xmlDocument );

final JaxbEntityMappingsImpl jaxbRoot = binding.getRoot();
persistenceUnitMetadata.apply( jaxbRoot.getPersistenceUnitMetadata() );
jaxbRoot.getEmbeddables().forEach( (jaxbEmbeddable) -> {
if ( StringHelper.isNotEmpty( jaxbEmbeddable.getClazz() ) ) {
managedClasses.add( XmlProcessingHelper.determineClassName( document, jaxbEmbeddable ) );
managedClasses.add( XmlProcessingHelper.determineClassName( jaxbRoot, jaxbEmbeddable ) );
}
else if ( StringHelper.isNotEmpty( jaxbEmbeddable.getName() ) ) {
managedNames.add( jaxbEmbeddable.getName() );
}
} );
document.getMappedSuperclasses().forEach( (jaxbMappedSuperclass) -> {
managedClasses.add( XmlProcessingHelper.determineClassName( document, jaxbMappedSuperclass ) );
jaxbRoot.getMappedSuperclasses().forEach( (jaxbMappedSuperclass) -> {
managedClasses.add( XmlProcessingHelper.determineClassName( jaxbRoot, jaxbMappedSuperclass ) );
} );
document.getEntities().forEach( (jaxbEntity) -> {
jaxbRoot.getEntities().forEach( (jaxbEntity) -> {
if ( StringHelper.isNotEmpty( jaxbEntity.getClazz() ) ) {
managedClasses.add( XmlProcessingHelper.determineClassName( document, jaxbEntity ) );
managedClasses.add( XmlProcessingHelper.determineClassName( jaxbRoot, jaxbEntity ) );
}
else if ( StringHelper.isNotEmpty( jaxbEntity.getName() ) ) {
managedNames.add( jaxbEntity.getName() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddableImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclassImpl;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.boot.models.xml.spi.XmlProcessingResult;

/**
Expand All @@ -34,7 +33,7 @@ public void addEmbeddableOverride(OverrideTuple<JaxbEmbeddableImpl> overrideTupl
}

@Override
public void apply(PersistenceUnitMetadata metadata) {
public void apply() {
ManagedTypeProcessor.processOverrideEmbeddable( getEmbeddableOverrides() );

ManagedTypeProcessor.processOverrideMappedSuperclass( getMappedSuperclassesOverrides() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.boot.models.annotations.internal.CollectionTableJpaAnnotation;
import org.hibernate.boot.models.annotations.internal.ElementCollectionJpaAnnotation;
import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation;
import org.hibernate.boot.models.xml.internal.SimpleTypeInterpretation;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
Expand Down Expand Up @@ -53,7 +54,7 @@ public static MutableMemberDetails processElementCollectionAttribute(
elementCollectionUsage.fetch( jaxbElementCollection.getFetch() );
}

applyTarget( jaxbElementCollection, xmlDocumentContext, memberDetails );
applyElementCollectionElementType( jaxbElementCollection, elementCollectionUsage, memberDetails, xmlDocumentContext );

// NOTE: it is important that this happens before the `CommonPluralAttributeProcessing#applyPluralAttributeStructure`
// call below
Expand Down Expand Up @@ -91,6 +92,22 @@ public static MutableMemberDetails processElementCollectionAttribute(
return memberDetails;
}

private static void applyElementCollectionElementType(
JaxbElementCollectionImpl jaxbElementCollection,
ElementCollectionJpaAnnotation elementCollectionUsage,
MutableMemberDetails memberDetails,
XmlDocumentContext xmlDocumentContext) {
if ( StringHelper.isNotEmpty( jaxbElementCollection.getTargetClass() ) ) {
final SimpleTypeInterpretation simpleTypeInterpretation = SimpleTypeInterpretation.interpret( jaxbElementCollection.getTargetClass() );
if ( simpleTypeInterpretation != null ) {
elementCollectionUsage.targetClass( simpleTypeInterpretation.getJavaType() );
return;
}
}

applyTarget( jaxbElementCollection, xmlDocumentContext, memberDetails );
}

private static void applyTarget(
JaxbElementCollectionImpl jaxbElementCollection,
XmlDocumentContext xmlDocumentContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
*/
package org.hibernate.boot.models.xml.spi;

import java.util.List;
import java.util.Map;

import jakarta.persistence.AccessType;
import org.hibernate.boot.jaxb.Origin;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedNativeQueryType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedQueryType;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCollectionUserTypeRegistrationImpl;
Expand All @@ -16,20 +15,26 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddableImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddableInstantiatorRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbJavaTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbJdbcTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclassImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeRegistrationImpl;

import jakarta.persistence.AccessType;
import java.util.List;
import java.util.Map;

/**
* @author Steve Ebersole
*/
public interface XmlDocument {
Origin getOrigin();

JaxbEntityMappingsImpl getRoot();

List<JaxbEntityImpl> getEntityMappings();

List<JaxbMappedSuperclassImpl> getMappedSuperclassMappings();
Expand Down
Loading