diff --git a/hibernate-core/src/main/java/org/hibernate/engine/FetchStrategy.java b/hibernate-core/src/main/java/org/hibernate/engine/FetchStrategy.java index 22f137d5e3..98c6e5a49f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/FetchStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/FetchStrategy.java @@ -6,12 +6,14 @@ */ package org.hibernate.engine; +import org.hibernate.sql.results.graph.FetchOptions; + /** * Describes the strategy for fetching an association, which includes both when and how. * * @author Steve Ebersole */ -public class FetchStrategy { +public class FetchStrategy implements FetchOptions { public static FetchStrategy IMMEDIATE_JOIN = new FetchStrategy( FetchTiming.IMMEDIATE, FetchStyle.JOIN ); private final FetchTiming timing; @@ -28,10 +30,12 @@ public FetchStrategy(FetchTiming timing, FetchStyle style) { this.style = style; } + @Override public FetchTiming getTiming() { return timing; } + @Override public FetchStyle getStyle() { return style; } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java index b49f064b3a..e5928b0c69 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java @@ -455,8 +455,8 @@ private BiConsumer createFetchableBiConsumer( } final LockMode lockMode = LockMode.READ; - FetchTiming fetchTiming = fetchable.getMappedFetchStrategy().getTiming(); - boolean joined = fetchable.getMappedFetchStrategy().getStyle() == FetchStyle.JOIN; + FetchTiming fetchTiming = fetchable.getMappedFetchOptions().getTiming(); + boolean joined = fetchable.getMappedFetchOptions().getStyle() == FetchStyle.JOIN; EntityGraphTraversalState.TraversalResult traversalResult = null; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityDiscriminatorMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityDiscriminatorMapping.java index 416b539348..63c3c82036 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityDiscriminatorMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityDiscriminatorMapping.java @@ -7,7 +7,7 @@ package org.hibernate.metamodel.mapping.internal; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping; import org.hibernate.metamodel.mapping.JdbcMapping; @@ -20,6 +20,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.sql.results.graph.basic.BasicResult; @@ -29,7 +30,7 @@ /** * @author Andrea Boriero */ -public abstract class AbstractEntityDiscriminatorMapping implements EntityDiscriminatorMapping { +public abstract class AbstractEntityDiscriminatorMapping implements EntityDiscriminatorMapping, FetchOptions { private final EntityPersister entityDescriptor; private final String tableExpression; private final String mappedColumnExpression; @@ -67,8 +68,18 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return FetchStrategy.IMMEDIATE_JOIN; + public FetchOptions getMappedFetchOptions() { + return this; + } + + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java index cf06a1fd1d..dacf9e2e82 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java @@ -7,32 +7,54 @@ package org.hibernate.metamodel.mapping.internal; import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; +import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.StateArrayContributorMapping; import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess; +import org.hibernate.sql.results.graph.FetchOptions; /** * @author Steve Ebersole */ public abstract class AbstractStateArrayContributorMapping extends AbstractAttributeMapping - implements StateArrayContributorMapping { + implements StateArrayContributorMapping, FetchOptions { private final StateArrayContributorMetadataAccess attributeMetadataAccess; + private final FetchTiming fetchTiming; + private final FetchStyle fetchStyle; private final int stateArrayPosition; - private final FetchStrategy mappedFetchStrategy; + public AbstractStateArrayContributorMapping( + String name, + StateArrayContributorMetadataAccess attributeMetadataAccess, + FetchTiming fetchTiming, + FetchStyle fetchStyle, + int stateArrayPosition, + ManagedMappingType declaringType) { + super( name, declaringType ); + this.attributeMetadataAccess = attributeMetadataAccess; + this.fetchTiming = fetchTiming; + this.fetchStyle = fetchStyle; + this.stateArrayPosition = stateArrayPosition; + } + public AbstractStateArrayContributorMapping( String name, StateArrayContributorMetadataAccess attributeMetadataAccess, FetchStrategy mappedFetchStrategy, int stateArrayPosition, ManagedMappingType declaringType) { - super( name, declaringType ); - this.attributeMetadataAccess = attributeMetadataAccess; - this.mappedFetchStrategy = mappedFetchStrategy; - this.stateArrayPosition = stateArrayPosition; + this( + name, + attributeMetadataAccess, + mappedFetchStrategy.getTiming(), + mappedFetchStrategy.getStyle(), + stateArrayPosition, + declaringType + ); } @Override @@ -51,7 +73,17 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return mappedFetchStrategy; + public FetchOptions getMappedFetchOptions() { + return this; + } + + @Override + public FetchStyle getStyle() { + return fetchStyle; + } + + @Override + public FetchTiming getTiming() { + return fetchTiming; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java index ee43419570..c8280850f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java @@ -10,9 +10,8 @@ import java.util.function.Consumer; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; -import org.hibernate.engine.spi.ManagedEntity; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.mapping.PersistentClass; @@ -39,6 +38,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.sql.results.graph.basic.BasicResult; @@ -49,7 +49,7 @@ /** * @author Andrea Boriero */ -public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMapping { +public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMapping, FetchOptions { private final PropertyAccess propertyAccess; private final EntityPersister entityPersister; private final SessionFactoryImplementor sessionFactory; @@ -258,8 +258,8 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return FetchStrategy.IMMEDIATE_JOIN; + public FetchOptions getMappedFetchOptions() { + return this; } @Override @@ -282,4 +282,14 @@ public Fetch generateFetch( creationState ); } + + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java index 860416f062..de57b8b362 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java @@ -10,7 +10,7 @@ import java.util.List; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.mapping.BasicValuedModelPart; import org.hibernate.metamodel.mapping.CollectionPart; @@ -30,10 +30,10 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.sql.results.graph.basic.BasicResult; -import org.hibernate.type.BasicType; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; @@ -42,7 +42,8 @@ * * @author Steve Ebersole */ -public class BasicValuedCollectionPart implements CollectionPart, BasicValuedModelPart, ConvertibleModelPart { +public class BasicValuedCollectionPart + implements CollectionPart, BasicValuedModelPart, ConvertibleModelPart, FetchOptions { private final NavigableRole navigableRole; private final CollectionPersister collectionDescriptor; private final Nature nature; @@ -166,8 +167,8 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return FetchStrategy.IMMEDIATE_JOIN; + public FetchOptions getMappedFetchOptions() { + return this; } @Override @@ -212,6 +213,16 @@ public List getJdbcMappings(TypeConfiguration typeConfiguration) { return Collections.singletonList( getJdbcMapping() ); } + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; + } + // // @Override // public BasicType getBasicType() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java index d416e90f52..62502cf4dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java @@ -7,7 +7,7 @@ package org.hibernate.metamodel.mapping.internal; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.CollectionIdentifierDescriptor; @@ -27,6 +27,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.sql.results.graph.basic.BasicResult; @@ -36,7 +37,7 @@ /** * @author Steve Ebersole */ -public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierDescriptor { +public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierDescriptor, FetchOptions { private final NavigableRole navigableRole; private final CollectionPersister collectionDescriptor; private final String containingTableName; @@ -106,8 +107,8 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return null; + public FetchOptions getMappedFetchOptions() { + return this; } @Override @@ -196,4 +197,14 @@ public DomainResult createDomainResult( public String toString() { return getClass().getSimpleName() + "(" + collectionDescriptor.getRole() + ")"; } + + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java index 7d73aadd67..96d7394a7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java @@ -12,6 +12,7 @@ import org.hibernate.LockMode; import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.mapping.CollectionPart; @@ -40,6 +41,7 @@ import org.hibernate.sql.ast.tree.from.TableGroupJoin; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.embeddable.EmbeddableValuedFetchable; import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableFetchImpl; @@ -49,7 +51,7 @@ /** * @author Steve Ebersole */ -public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedFetchable { +public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedFetchable, FetchOptions { private final NavigableRole navigableRole; private final CollectionPersister collectionDescriptor; private final Nature nature; @@ -116,10 +118,11 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return FetchStrategy.IMMEDIATE_JOIN; + public FetchOptions getMappedFetchOptions() { + return this; } + @Override public int getJdbcTypeCount(TypeConfiguration typeConfiguration) { return getEmbeddableTypeDescriptor().getJdbcTypeCount( typeConfiguration ); @@ -251,4 +254,14 @@ public EntityMappingType findContainingEntityMapping() { public int getNumberOfFetchables() { return getEmbeddableTypeDescriptor().getNumberOfAttributeMappings(); } + + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java index d66dfcb059..7358b0b633 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java @@ -12,7 +12,7 @@ import java.util.function.Consumer; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -48,6 +48,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.embeddable.EmbeddableValuedFetchable; import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableFetchImpl; @@ -60,7 +61,8 @@ * * @author Andrea Boriero */ -public class EmbeddedIdentifierMappingImpl implements CompositeIdentifierMapping, EmbeddableValuedFetchable { +public class EmbeddedIdentifierMappingImpl + implements CompositeIdentifierMapping, EmbeddableValuedFetchable, FetchOptions { private final NavigableRole navigableRole; private final EntityMappingType entityMapping; private final String name; @@ -285,8 +287,8 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return null; + public FetchOptions getMappedFetchOptions() { + return this; } @Override @@ -345,4 +347,13 @@ public Collection getAttributes() { return (Collection) getEmbeddableTypeDescriptor().getAttributeMappings(); } + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityCollectionPart.java index 42e9678e9b..38da2e76ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityCollectionPart.java @@ -6,12 +6,9 @@ */ package org.hibernate.metamodel.mapping.internal; -import java.util.ArrayList; -import java.util.List; - import org.hibernate.LockMode; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Value; @@ -29,6 +26,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.collection.internal.EntityCollectionPartTableGroup; import org.hibernate.sql.results.graph.entity.EntityFetch; @@ -40,7 +38,7 @@ * @author Steve Ebersole */ public class EntityCollectionPart - implements CollectionPart, EntityAssociationMapping, EntityValuedFetchable, Association { + implements CollectionPart, EntityAssociationMapping, EntityValuedFetchable, Association, FetchOptions { private final NavigableRole navigableRole; private final CollectionPersister collectionDescriptor; private final Nature nature; @@ -118,8 +116,8 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return FetchStrategy.IMMEDIATE_JOIN; + public FetchOptions getMappedFetchOptions() { + return this; } @Override @@ -203,4 +201,14 @@ public ForeignKeyDescriptor getForeignKeyDescriptor() { // todo (6.0) : this will not strictly work - we'd want a new ForeignKeyDescriptor that points the other direction return collectionDescriptor.getAttributeMapping().getKeyDescriptor(); } + + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java index 8eb1782f4b..0b275f7065 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java @@ -9,7 +9,7 @@ import java.util.function.BiConsumer; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.mapping.ColumnConsumer; import org.hibernate.metamodel.mapping.EntityMappingType; @@ -27,6 +27,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.sql.results.graph.basic.BasicResult; @@ -36,7 +37,7 @@ /** * @author Steve Ebersole */ -public class EntityVersionMappingImpl implements EntityVersionMapping { +public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOptions { private final String attributeName; private final EntityMappingType declaringType; @@ -116,8 +117,8 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return FetchStrategy.IMMEDIATE_JOIN; + public FetchOptions getMappedFetchOptions() { + return this; } @Override @@ -214,4 +215,14 @@ public void applySqlSelections( public void visitColumns(ColumnConsumer consumer) { } + + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java index 29bbb99f35..0bc83a7453 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java @@ -12,7 +12,7 @@ import java.util.function.Consumer; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.mapping.Component; @@ -39,6 +39,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.embeddable.EmbeddableValuedFetchable; import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableFetchImpl; @@ -54,7 +55,8 @@ * * @author Steve Ebersole */ -public class NonAggregatedIdentifierMappingImpl implements CompositeIdentifierMapping, EmbeddableValuedFetchable { +public class NonAggregatedIdentifierMappingImpl + implements CompositeIdentifierMapping, EmbeddableValuedFetchable, FetchOptions { private final EmbeddableMappingType embeddableDescriptor; private final NavigableRole navigableRole; private final EntityMappingType entityMapping; @@ -228,8 +230,8 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return null; + public FetchOptions getMappedFetchOptions() { + return this; } @Override @@ -256,4 +258,14 @@ public Fetch generateFetch( public int getNumberOfFetchables() { return idAttributeMappings.size(); } + + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java index e7bbd88fa9..0d5788a3fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java @@ -14,6 +14,7 @@ import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.dialect.Dialect; import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.LoadQueryInfluencers; @@ -59,6 +60,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult; import org.hibernate.sql.results.graph.collection.internal.DelayedCollectionFetch; @@ -71,7 +73,8 @@ /** * @author Steve Ebersole */ -public class PluralAttributeMappingImpl extends AbstractAttributeMapping implements PluralAttributeMapping { +public class PluralAttributeMappingImpl extends AbstractAttributeMapping implements PluralAttributeMapping, + FetchOptions { private static final Logger log = Logger.getLogger( PluralAttributeMappingImpl.class ); public interface Aware { @@ -87,8 +90,9 @@ public interface Aware { private final CollectionPart elementDescriptor; private final CollectionPart indexDescriptor; private final CollectionIdentifierDescriptor identifierDescriptor; + private final FetchTiming fetchTiming; + private final FetchStyle fetchStyle; - private final FetchStrategy fetchStrategy; private final CascadeStyle cascadeStyle; private final CollectionPersister collectionDescriptor; @@ -119,6 +123,40 @@ public PluralAttributeMappingImpl( CascadeStyle cascadeStyle, ManagedMappingType declaringType, CollectionPersister collectionDescriptor) { + this( + attributeName, + bootDescriptor, + propertyAccess, + stateArrayContributorMetadataAccess, + collectionMappingType, + stateArrayPosition, + elementDescriptor, + indexDescriptor, + identifierDescriptor, + fetchStrategy.getTiming(), + fetchStrategy.getStyle(), + cascadeStyle, + declaringType, + collectionDescriptor + ); + } + + @SuppressWarnings({"WeakerAccess", "rawtypes"}) + public PluralAttributeMappingImpl( + String attributeName, + Collection bootDescriptor, + PropertyAccess propertyAccess, + StateArrayContributorMetadataAccess stateArrayContributorMetadataAccess, + CollectionMappingType collectionMappingType, + int stateArrayPosition, + CollectionPart elementDescriptor, + CollectionPart indexDescriptor, + CollectionIdentifierDescriptor identifierDescriptor, + FetchTiming fetchTiming, + FetchStyle fetchStyle, + CascadeStyle cascadeStyle, + ManagedMappingType declaringType, + CollectionPersister collectionDescriptor) { super( attributeName, declaringType ); this.propertyAccess = propertyAccess; this.stateArrayContributorMetadataAccess = stateArrayContributorMetadataAccess; @@ -127,7 +165,8 @@ public PluralAttributeMappingImpl( this.elementDescriptor = elementDescriptor; this.indexDescriptor = indexDescriptor; this.identifierDescriptor = identifierDescriptor; - this.fetchStrategy = fetchStrategy; + this.fetchTiming = fetchTiming; + this.fetchStyle = fetchStyle; this.cascadeStyle = cascadeStyle; this.collectionDescriptor = collectionDescriptor; @@ -281,6 +320,11 @@ public JpaCompliance getJpaCompliance() { } } + @Override + public NavigableRole getNavigableRole() { + return getCollectionDescriptor().getNavigableRole(); + } + @Override @SuppressWarnings("rawtypes") public CollectionMappingType getMappedTypeDescriptor() { @@ -353,13 +397,18 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return fetchStrategy; + public FetchOptions getMappedFetchOptions() { + return this; } @Override - public NavigableRole getNavigableRole() { - return getCollectionDescriptor().getNavigableRole(); + public FetchStyle getStyle() { + return fetchStyle; + } + + @Override + public FetchTiming getTiming() { + return fetchTiming; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java index 29eabf5aae..126f61fa7a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java @@ -11,7 +11,7 @@ import java.util.function.Consumer; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.mapping.BasicValuedModelPart; @@ -38,6 +38,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.basic.BasicResult; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -46,7 +47,7 @@ /** * @author Steve Ebersole */ -public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicValuedModelPart { +public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicValuedModelPart, FetchOptions { private final String keyColumnContainingTable; private final String keyColumnExpression; private final String targetColumnContainingTable; @@ -356,8 +357,18 @@ public String getFetchableName() { } @Override - public FetchStrategy getMappedFetchStrategy() { - return FetchStrategy.IMMEDIATE_JOIN; + public FetchOptions getMappedFetchOptions() { + return this; + } + + @Override + public FetchStyle getStyle() { + return FetchStyle.JOIN; + } + + @Override + public FetchTiming getTiming() { + return FetchTiming.IMMEDIATE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmSelectTranslator.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmSelectTranslator.java index b802a6fd87..e4bfa9a3a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmSelectTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmSelectTranslator.java @@ -307,7 +307,7 @@ private Fetch buildFetch(NavigablePath fetchablePath, FetchParent fetchParent, F final String alias; LockMode lockMode = LockMode.READ; - FetchTiming fetchTiming = fetchable.getMappedFetchStrategy().getTiming(); + FetchTiming fetchTiming = fetchable.getMappedFetchOptions().getTiming(); boolean joined = false; EntityGraphTraversalState.TraversalResult traversalResult = null; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetch.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetch.java index f74a5eed3c..bb0ddc835e 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetch.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetch.java @@ -6,8 +6,6 @@ */ package org.hibernate.sql.results.graph; -import java.util.function.Consumer; - import org.hibernate.engine.FetchTiming; import org.hibernate.query.NavigablePath; @@ -48,6 +46,8 @@ public interface Fetch extends DomainResultGraphNode { /** * immediate or delayed? + * + * todo (6.0) : should we also expose the fetch-style? Perhaps the fetch-options? */ FetchTiming getTiming(); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchOptions.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchOptions.java new file mode 100644 index 0000000000..63fb76739d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchOptions.java @@ -0,0 +1,18 @@ +/* + * 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.sql.results.graph; + +import org.hibernate.engine.FetchStyle; +import org.hibernate.engine.FetchTiming; + +/** + * Represents an aggregated {@link FetchTiming} and {@link FetchStyle} value + * + * @author Steve Ebersole + */ +public interface FetchOptions extends FetchTimingAccess, FetchStyleAccess { +} diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchStyleAccess.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchStyleAccess.java new file mode 100644 index 0000000000..4732a6eeeb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchStyleAccess.java @@ -0,0 +1,18 @@ +/* + * 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.sql.results.graph; + +import org.hibernate.engine.FetchStyle; + +/** + * Access to a FetchStyle + * + * @author Steve Ebersole + */ +public interface FetchStyleAccess { + FetchStyle getStyle(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchTimingAccess.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchTimingAccess.java new file mode 100644 index 0000000000..2f7924dc93 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchTimingAccess.java @@ -0,0 +1,18 @@ +/* + * 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.sql.results.graph; + +import org.hibernate.engine.FetchTiming; + +/** + * Access to a FetchTiming + * + * @author Steve Ebersole + */ +public interface FetchTimingAccess { + FetchTiming getTiming(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetchable.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetchable.java index 35b638a735..edc726a14b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetchable.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetchable.java @@ -7,7 +7,6 @@ package org.hibernate.sql.results.graph; import org.hibernate.LockMode; -import org.hibernate.engine.FetchStrategy; import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.query.NavigablePath; @@ -18,7 +17,7 @@ public interface Fetchable extends ModelPart { String getFetchableName(); - FetchStrategy getMappedFetchStrategy(); + FetchOptions getMappedFetchOptions(); // todo (6.0) : all we need here is (1) FetchTiming and (2) whether the values are available in the current JdbcValuesSource // Having to instantiate new FetchStrategy potentially multiple times diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableForeignKeyResultImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableForeignKeyResultImpl.java index 9b9682adc0..72f641633a 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableForeignKeyResultImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableForeignKeyResultImpl.java @@ -75,7 +75,7 @@ private void generateFetches( associatedEntityMappingType.getIdentifierMapping().getJavaTypeDescriptor() ); Fetch fetch; - if ( toOneAttributeMapping.getMappedFetchStrategy().getTiming() == FetchTiming.DELAYED ) { + if ( toOneAttributeMapping.getMappedFetchOptions().getTiming() == FetchTiming.DELAYED ) { fetch = new EntityFetchDelayedImpl( this, toOneAttributeMapping, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/StandardEntityGraphTraversalStateImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/StandardEntityGraphTraversalStateImpl.java index 895dcfe932..c694005b16 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/StandardEntityGraphTraversalStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/StandardEntityGraphTraversalStateImpl.java @@ -97,8 +97,8 @@ assert exploreKeySubgraph && isJpaMapCollectionType( pluralAttributeMapping ) joined = false; } else { - fetchTiming = fetchable.getMappedFetchStrategy().getTiming(); - joined = fetchable.getMappedFetchStrategy().getStyle() == FetchStyle.JOIN; + fetchTiming = fetchable.getMappedFetchOptions().getTiming(); + joined = fetchable.getMappedFetchOptions().getStyle() == FetchStyle.JOIN; } } return new TraversalResult( previousContextRoot, fetchTiming, joined ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/BiDirectionalFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/BiDirectionalFetchImpl.java index 5b8597c246..9f073ebd39 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/BiDirectionalFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/BiDirectionalFetchImpl.java @@ -137,7 +137,7 @@ public JavaTypeDescriptor getJavaTypeDescriptor() { } @Override - public FetchStrategy getMappedFetchStrategy() { + public FetchStrategy getMappedFetchOptions() { throw new UnsupportedOperationException(); }