From 1c87d73d2e96b7be0250ff7035175acf7e56fc23 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Fri, 20 Sep 2024 11:37:12 +0200 Subject: [PATCH] =?UTF-8?q?HHH-18569=20Don=C2=B4t=20implicitly=20cast=20wh?= =?UTF-8?q?en=20using=20a=20subtype=20attribute=20name=20with=20Criteria?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/AbstractPluralAttribute.java | 5 +- .../domain/internal/EntitySqmPathSource.java | 5 +- .../model/domain/internal/EntityTypeImpl.java | 16 +++--- .../domain/internal/ListAttributeImpl.java | 5 +- .../domain/internal/MapAttributeImpl.java | 5 +- .../internal/SingularAttributeImpl.java | 5 +- .../internal/BasicDotIdentifierConsumer.java | 2 +- .../internal/QualifiedJoinPathConsumer.java | 5 +- .../hql/internal/SemanticQueryBuilder.java | 2 +- .../hql/internal/SqmPathRegistryImpl.java | 2 +- .../hibernate/query/sqm/SqmPathSource.java | 49 +++++++++++++++++-- .../sqm/tree/domain/AbstractSqmFrom.java | 18 +++---- .../sqm/tree/domain/AbstractSqmPath.java | 11 ++++- .../tree/domain/SqmAnyValuedSimplePath.java | 2 +- .../domain/SqmElementAggregateFunction.java | 2 +- .../domain/SqmEmbeddedValuedSimplePath.java | 2 +- .../domain/SqmEntityValuedSimplePath.java | 2 +- .../sqm/tree/domain/SqmFkExpression.java | 2 +- .../sqm/tree/domain/SqmFunctionPath.java | 2 +- .../domain/SqmIndexAggregateFunction.java | 2 +- .../SqmIndexedCollectionAccessPath.java | 2 +- .../query/sqm/tree/domain/SqmPath.java | 10 ++++ .../domain/SqmPluralValuedSimplePath.java | 2 +- .../query/sqm/tree/domain/SqmSetJoin.java | 9 ---- .../SqmTreatedEmbeddedValuedSimplePath.java | 2 +- .../query/sqm/tree/domain/SqmTreatedRoot.java | 2 +- .../query/sqm/tree/select/SqmQuerySpec.java | 14 +++--- .../TreatedSubclassSameTypeTest.java | 5 -- .../joinedsubclass/JoinedSubclassTest.java | 2 +- .../CorrelatedPluralJoinInheritanceTest.java | 7 ++- .../discriminator/DiscriminatorTest.java | 2 +- .../discriminator/SimpleInheritanceTest.java | 2 +- .../criteria/CriteriaInheritanceJoinTest.java | 2 +- .../unionsubclass2/UnionSubclassTest.java | 2 +- migration-guide.adoc | 7 +++ .../validation/MockSessionFactory.java | 5 +- 36 files changed, 130 insertions(+), 89 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java index 77c97efeb4..eb1334f5e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java @@ -12,7 +12,6 @@ import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.mapping.CollectionPart; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.spi.NavigablePath; @@ -87,11 +86,11 @@ public abstract class AbstractPluralAttribute } @Override - public SqmPathSource findSubPathSource(String name, JpaMetamodel metamodel) { + public SqmPathSource findSubPathSource(String name, boolean includeSubtypes) { if ( CollectionPart.Nature.ELEMENT.getName().equals( name ) ) { return elementPathSource; } - return elementPathSource.findSubPathSource( name, metamodel ); + return elementPathSource.findSubPathSource( name, includeSubtypes ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java index df09e53e1c..c093dfe198 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java @@ -5,7 +5,6 @@ package org.hibernate.metamodel.model.domain.internal; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.query.hql.spi.SqmCreationState; import org.hibernate.query.sqm.SqmJoinable; import org.hibernate.query.sqm.SqmPathSource; @@ -42,8 +41,8 @@ public class EntitySqmPathSource extends AbstractSqmPathSource implements } @Override - public SqmPathSource findSubPathSource(String name, JpaMetamodel metamodel) { - return getSqmPathType().findSubPathSource( name, metamodel ); + public SqmPathSource findSubPathSource(String name, boolean includeSubtypes) { + return getSqmPathType().findSubPathSource( name, includeSubtypes ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java index 7b302907c7..4265fa5d6d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java @@ -139,14 +139,13 @@ public class EntityTypeImpl @Override public SqmPathSource findSubPathSource(String name) { - final PersistentAttribute attribute = findAttribute( name ); + final PersistentAttribute attribute = super.findAttribute( name ); if ( attribute != null ) { return (SqmPathSource) attribute; } else if ( EntityIdentifierMapping.matchesRoleName( name ) ) { return hasSingleIdAttribute() ? findIdAttribute() : getIdentifierDescriptor(); } - else if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) { return discriminatorPathSource; } @@ -156,18 +155,19 @@ public class EntityTypeImpl } @Override - public SqmPathSource findSubPathSource(String name, JpaMetamodel metamodel) { + public SqmPathSource findSubPathSource(String name, boolean includeSubtypes) { final PersistentAttribute attribute = super.findAttribute( name ); if ( attribute != null ) { return (SqmPathSource) attribute; } else { - //TODO: eliminate this cast! - final PersistentAttribute subtypeAttribute = findSubtypeAttribute( name ); - if ( subtypeAttribute != null ) { - return (SqmPathSource) subtypeAttribute; + if ( includeSubtypes ) { + final PersistentAttribute subtypeAttribute = findSubtypeAttribute( name ); + if ( subtypeAttribute != null ) { + return (SqmPathSource) subtypeAttribute; + } } - else if ( EntityIdentifierMapping.matchesRoleName( name ) ) { + if ( EntityIdentifierMapping.matchesRoleName( name ) ) { return hasSingleIdAttribute() ? findIdAttribute() : getIdentifierDescriptor(); } else if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java index 5843a2d8be..93310d8603 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java @@ -8,7 +8,6 @@ import java.util.List; import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.mapping.CollectionPart; -import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ListPersistentAttribute; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.hql.spi.SqmCreationState; @@ -60,7 +59,7 @@ public class ListAttributeImpl extends AbstractPluralAttribute, } @Override - public SqmPathSource findSubPathSource(String name, JpaMetamodel metamodel) { + public SqmPathSource findSubPathSource(String name, boolean includeSubtypes) { final CollectionPart.Nature nature = CollectionPart.Nature.fromNameExact( name ); if ( nature != null ) { switch ( nature ) { @@ -70,7 +69,7 @@ public class ListAttributeImpl extends AbstractPluralAttribute, return getElementPathSource(); } } - return getElementPathSource().findSubPathSource( name, metamodel ); + return getElementPathSource().findSubPathSource( name, includeSubtypes ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java index 03b60c4e05..1930bbcc91 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java @@ -8,7 +8,6 @@ import java.util.Map; import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.mapping.CollectionPart; -import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.MapPersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.query.sqm.SqmPathSource; @@ -70,7 +69,7 @@ public class MapAttributeImpl extends AbstractPluralAttribute findSubPathSource(String name, JpaMetamodel metamodel) { + public SqmPathSource findSubPathSource(String name, boolean includeSubtypes) { final CollectionPart.Nature nature = CollectionPart.Nature.fromNameExact( name ); if ( nature != null ) { switch ( nature ) { @@ -80,7 +79,7 @@ public class MapAttributeImpl extends AbstractPluralAttribute } @Override - public SqmPathSource findSubPathSource(String name, JpaMetamodel metamodel) { - return sqmPathSource.findSubPathSource( name, metamodel ); + public SqmPathSource findSubPathSource(String name, boolean includeSubtypes) { + return sqmPathSource.findSubPathSource( name, includeSubtypes ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java index 0c3ffb536c..547ef4c3fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java @@ -145,7 +145,7 @@ public class BasicDotIdentifierConsumer implements DotIdentifierConsumer { if ( pathRootByExposedNavigable != null ) { // identifier is an "unqualified attribute reference" validateAsRoot( pathRootByExposedNavigable ); - final SqmPath sqmPath = pathRootByExposedNavigable.get( identifier ); + final SqmPath sqmPath = pathRootByExposedNavigable.get( identifier, true ); return isTerminal ? sqmPath : new DomainPathPart( sqmPath ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java index c58e961d8d..267af7c49f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java @@ -188,10 +188,7 @@ public class QualifiedJoinPathConsumer implements DotIdentifierConsumer { boolean isTerminal, boolean allowReuse, SqmCreationState creationState) { - final SqmPathSource subPathSource = lhs.getResolvedModel().getSubPathSource( - name, - creationState.getCreationContext().getJpaMetamodel() - ); + final SqmPathSource subPathSource = lhs.getResolvedModel().getSubPathSource( name, true ); if ( allowReuse ) { if ( !isTerminal ) { for ( SqmJoin sqmJoin : lhs.getSqmJoins() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index a930b02b45..86060dbbfd 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -3587,7 +3587,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem + "' of 'id()' is a '" + identifiableType.getTypeName() + "' and does not have a well-defined '@Id' attribute" ); } - return sqmPath.get( identifierDescriptor.getPathName() ); + return sqmPath.get( identifierDescriptor.getPathName(), true ); } else if ( sqmPath instanceof SqmAnyValuedSimplePath ) { return sqmPath.resolvePathPart( AnyKeyPart.KEY_NAME, true, processingStateStack.getCurrent().getCreationState() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SqmPathRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SqmPathRegistryImpl.java index c3825f0908..ef568827e2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SqmPathRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SqmPathRegistryImpl.java @@ -335,7 +335,7 @@ public class SqmPathRegistryImpl implements SqmPathRegistry { private boolean definesAttribute(SqmPathSource containerType, String name) { return !( containerType.getSqmType() instanceof BasicDomainType ) - && containerType.findSubPathSource( name, getJpaMetamodel() ) != null; + && containerType.findSubPathSource( name, true ) != null; } private JpaMetamodel getJpaMetamodel() { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmPathSource.java index c9832dac35..b9ce05ee18 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmPathSource.java @@ -42,8 +42,8 @@ public interface SqmPathSource extends SqmExpressible, Bindable, SqmExp /** * Find a {@link SqmPathSource} by name relative to this source. * + * @param name the name of the path source to find * @return null if the subPathSource is not found - * * @throws IllegalStateException to indicate that this source cannot be de-referenced */ SqmPathSource findSubPathSource(String name); @@ -52,16 +52,31 @@ public interface SqmPathSource extends SqmExpressible, Bindable, SqmExp * Find a {@link SqmPathSource} by name relative to this source. * * @return null if the subPathSource is not found + * @throws IllegalStateException to indicate that this source cannot be de-referenced + * @deprecated Use {@link #findSubPathSource(String, boolean)} instead + */ + @Deprecated(forRemoval = true, since = "7.0") + default SqmPathSource findSubPathSource(String name, JpaMetamodel metamodel) { + return findSubPathSource( name, true ); + } + + /** + * Find a {@link SqmPathSource} by name relative to this source. If {@code includeSubtypes} is set + * to {@code true} and this path source is polymorphic, also try finding subtype attributes. * + * @param name the name of the path source to find + * @param includeSubtypes flag indicating whether to consider subtype attributes + * @return null if the subPathSource is not found * @throws IllegalStateException to indicate that this source cannot be de-referenced */ - default SqmPathSource findSubPathSource(String name, JpaMetamodel metamodel) { + default SqmPathSource findSubPathSource(String name, boolean includeSubtypes) { return findSubPathSource( name ); } /** * Find a {@link SqmPathSource} by name relative to this source. * + * @param name the name of the path source to find * @throws IllegalStateException to indicate that this source cannot be de-referenced * @throws IllegalArgumentException if the subPathSource is not found */ @@ -81,13 +96,39 @@ public interface SqmPathSource extends SqmExpressible, Bindable, SqmExp } /** - * Find a {@link SqmPathSource} by name relative to this source. + * Find a {@link SqmPathSource} by name relative to this source and all its subtypes. * * @throws IllegalStateException to indicate that this source cannot be de-referenced * @throws IllegalArgumentException if the subPathSource is not found + * @deprecated Use #{@link #getSubPathSource(String, boolean)} instead */ + @Deprecated(forRemoval = true, since = "7.0") default SqmPathSource getSubPathSource(String name, JpaMetamodel metamodel) { - final SqmPathSource subPathSource = findSubPathSource( name, metamodel ); + final SqmPathSource subPathSource = findSubPathSource( name, true ); + if ( subPathSource == null ) { + throw new PathElementException( + String.format( + Locale.ROOT, + "Could not resolve attribute '%s' of '%s'", + name, + getExpressible().getTypeName() + ) + ); + } + return subPathSource; + } + + /** + * Find a {@link SqmPathSource} by name relative to this source. If {@code subtypes} is set + * to {@code true} and this path source is polymorphic, also try finding subtype attributes. + * + * @param name the name of the path source to find + * @param subtypes flag indicating whether to consider subtype attributes + * @throws IllegalStateException to indicate that this source cannot be de-referenced + * @throws IllegalArgumentException if the subPathSource is not found + */ + default SqmPathSource getSubPathSource(String name, boolean subtypes) { + final SqmPathSource subPathSource = findSubPathSource( name, true ); if ( subPathSource == null ) { throw new PathElementException( String.format( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java index d7d20501e9..e56c19ce90 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java @@ -196,7 +196,7 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements if ( resolvedPath != null ) { return resolvedPath; } - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } @@ -417,8 +417,8 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements @Override @SuppressWarnings("unchecked") public SqmAttributeJoin join(String attributeName, JoinType jt) { - final SqmPathSource subPathSource = - getReferencedPathSource().getSubPathSource( attributeName, nodeBuilder().getJpaMetamodel() ); + final SqmPathSource subPathSource = (SqmPathSource) getReferencedPathSource() + .getSubPathSource( attributeName ); return (SqmAttributeJoin) buildJoin( subPathSource, SqmJoinType.from( jt ), false ); } @@ -430,8 +430,7 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements @Override @SuppressWarnings("unchecked") public SqmBagJoin joinCollection(String attributeName, JoinType jt) { - final SqmPathSource joinedPathSource = - getReferencedPathSource().getSubPathSource( attributeName, nodeBuilder().getJpaMetamodel() ); + final SqmPathSource joinedPathSource = getReferencedPathSource().getSubPathSource( attributeName ); if ( joinedPathSource instanceof BagPersistentAttribute ) { final SqmBagJoin join = buildBagJoin( @@ -462,8 +461,7 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements @Override @SuppressWarnings("unchecked") public SqmSetJoin joinSet(String attributeName, JoinType jt) { - final SqmPathSource joinedPathSource = - getReferencedPathSource().getSubPathSource( attributeName, nodeBuilder().getJpaMetamodel() ); + final SqmPathSource joinedPathSource = getReferencedPathSource().getSubPathSource( attributeName ); if ( joinedPathSource instanceof SetPersistentAttribute ) { final SqmSetJoin join = buildSetJoin( @@ -494,8 +492,7 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements @Override @SuppressWarnings("unchecked") public SqmListJoin joinList(String attributeName, JoinType jt) { - final SqmPathSource joinedPathSource = - getReferencedPathSource().getSubPathSource( attributeName, nodeBuilder().getJpaMetamodel() ); + final SqmPathSource joinedPathSource = getReferencedPathSource().getSubPathSource( attributeName ); if ( joinedPathSource instanceof ListPersistentAttribute ) { final SqmListJoin join = buildListJoin( @@ -526,8 +523,7 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements @Override @SuppressWarnings("unchecked") public SqmMapJoin joinMap(String attributeName, JoinType jt) { - final SqmPathSource joinedPathSource = - getReferencedPathSource().getSubPathSource( attributeName, nodeBuilder().getJpaMetamodel() ); + final SqmPathSource joinedPathSource = getReferencedPathSource().getSubPathSource( attributeName ); if ( joinedPathSource instanceof MapPersistentAttribute ) { final SqmMapJoin join = buildMapJoin( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java index a8dff6b3f8..13e2f636af 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java @@ -193,11 +193,18 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem @Override public SqmPath get(String attributeName) { //noinspection unchecked - final SqmPathSource subNavigable = (SqmPathSource) - getResolvedModel().getSubPathSource( attributeName, nodeBuilder().getJpaMetamodel() ); + final SqmPathSource subNavigable = (SqmPathSource) getResolvedModel().getSubPathSource( attributeName ); return resolvePath( attributeName, subNavigable ); } + @Override + public SqmPath get(String attributeName, boolean includeSubtypes) { + //noinspection unchecked + final SqmPathSource subPathSource = (SqmPathSource) + getResolvedModel().getSubPathSource( attributeName, includeSubtypes ); + return resolvePath( attributeName, subPathSource ); + } + protected SqmPath resolvePath(PersistentAttribute attribute) { //noinspection unchecked return resolvePath( attribute.getName(), (SqmPathSource) attribute ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmAnyValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmAnyValuedSimplePath.java index 872a3cfbef..5b2eb9d994 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmAnyValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmAnyValuedSimplePath.java @@ -77,7 +77,7 @@ public class SqmAnyValuedSimplePath extends AbstractSqmSimplePath { String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmElementAggregateFunction.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmElementAggregateFunction.java index 608678463a..20ff1f4b32 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmElementAggregateFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmElementAggregateFunction.java @@ -100,7 +100,7 @@ public class SqmElementAggregateFunction extends AbstractSqmSpecificPluralPar String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEmbeddedValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEmbeddedValuedSimplePath.java index 906d11c590..67ac3a93eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEmbeddedValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEmbeddedValuedSimplePath.java @@ -84,7 +84,7 @@ public class SqmEmbeddedValuedSimplePath String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEntityValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEntityValuedSimplePath.java index 4e9eb78e3a..8d4e1cd6a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEntityValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEntityValuedSimplePath.java @@ -51,7 +51,7 @@ public class SqmEntityValuedSimplePath extends AbstractSqmSimplePath { String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmFkExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmFkExpression.java index 1ec52c4ef5..86db8f40b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmFkExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmFkExpression.java @@ -83,7 +83,7 @@ public class SqmFkExpression extends AbstractSqmPath { @Override public SqmPath resolvePathPart(String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmFunctionPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmFunctionPath.java index 0f8874f40e..61f212a92e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmFunctionPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmFunctionPath.java @@ -105,7 +105,7 @@ public class SqmFunctionPath extends AbstractSqmPath { String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmIndexAggregateFunction.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmIndexAggregateFunction.java index ff0124ba04..798222c1c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmIndexAggregateFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmIndexAggregateFunction.java @@ -102,7 +102,7 @@ public class SqmIndexAggregateFunction extends AbstractSqmSpecificPluralPartP String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmIndexedCollectionAccessPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmIndexedCollectionAccessPath.java index 5150cc7ae4..10e59cea75 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmIndexedCollectionAccessPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmIndexedCollectionAccessPath.java @@ -66,7 +66,7 @@ public class SqmIndexedCollectionAccessPath extends AbstractSqmPath implem String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPath.java index 63369de6a8..0a74df851a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPath.java @@ -175,6 +175,16 @@ public interface SqmPath extends SqmExpression, SemanticPathPart, JpaPath< @Override SqmPath get(String attributeName); + /** + * Same as {@link #get(String)}, but if {@code includeSubtypes} is set to {@code true} + * and this path is polymorphic, also try finding subtype attributes. + * + * @see SqmPathSource#findSubPathSource(String, boolean) + */ + default SqmPath get(String attributeName, boolean includeSubtypes) { + return get( attributeName ); + } + @Override SqmPath copy(SqmCopyContext context); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPluralValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPluralValuedSimplePath.java index 4d8c24e116..0cb3f562c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPluralValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPluralValuedSimplePath.java @@ -101,7 +101,7 @@ public class SqmPluralValuedSimplePath extends AbstractSqmSimplePath { + "' refers to a collection and so element attribute '" + name + "' may not be referenced directly (use element() function)" ); } - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSetJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSetJoin.java index 75fcffad52..ffbe6e751b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSetJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSetJoin.java @@ -18,11 +18,9 @@ import org.hibernate.query.criteria.JpaSetJoin; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmJoinType; -import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmFrom; import jakarta.persistence.criteria.Expression; -import jakarta.persistence.criteria.JoinType; import jakarta.persistence.criteria.Predicate; /** @@ -157,11 +155,4 @@ public class SqmSetJoin } return treat; } - - @Override - public SqmAttributeJoin fetch(String attributeName) { - return fetch( attributeName, JoinType.INNER); - } - - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedEmbeddedValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedEmbeddedValuedSimplePath.java index 6b7ebf61da..0140d8191c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedEmbeddedValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedEmbeddedValuedSimplePath.java @@ -103,7 +103,7 @@ public class SqmTreatedEmbeddedValuedSimplePath extends SqmEmbed @Override public SqmPath resolvePathPart(String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedRoot.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedRoot.java index e6f392fc7d..6b1c0ba3e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedRoot.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedRoot.java @@ -110,7 +110,7 @@ public class SqmTreatedRoot extends SqmRoot implements SqmTreatedFrom { String name, boolean isTerminal, SqmCreationState creationState) { - final SqmPath sqmPath = get( name ); + final SqmPath sqmPath = get( name, true ); creationState.getProcessingStateStack().getCurrent().getPathRegistry().register( sqmPath ); return sqmPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmQuerySpec.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmQuerySpec.java index 338ae5f86e..6e74afaece 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmQuerySpec.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmQuerySpec.java @@ -494,9 +494,9 @@ public class SqmQuerySpec extends SqmQueryPart } for ( SqmRoot root : roots ) { - validateFetchOwners( selectedFromSet, root, root ); + validateFetchOwners( selectedFromSet, root ); for ( SqmFrom sqmTreat : root.getSqmTreats() ) { - validateFetchOwners( selectedFromSet, root, sqmTreat ); + validateFetchOwners( selectedFromSet, sqmTreat ); } } } @@ -543,12 +543,12 @@ public class SqmQuerySpec extends SqmQueryPart } } - private void validateFetchOwners(Set> selectedFromSet, SqmFrom owner, SqmFrom joinContainer) { + private void validateFetchOwners(Set> selectedFromSet, SqmFrom joinContainer) { for ( SqmJoin sqmJoin : joinContainer.getSqmJoins() ) { if ( sqmJoin instanceof SqmAttributeJoin ) { final SqmAttributeJoin attributeJoin = (SqmAttributeJoin) sqmJoin; if ( attributeJoin.isFetched() ) { - assertFetchOwner( selectedFromSet, owner, sqmJoin ); + assertFetchOwner( selectedFromSet, attributeJoin.getLhs(), sqmJoin ); // Only need to check the first level continue; } @@ -557,14 +557,14 @@ public class SqmQuerySpec extends SqmQueryPart if ( sqmTreat instanceof SqmAttributeJoin ) { final SqmAttributeJoin attributeJoin = (SqmAttributeJoin) sqmTreat; if ( attributeJoin.isFetched() ) { - assertFetchOwner( selectedFromSet, owner, attributeJoin ); + assertFetchOwner( selectedFromSet, attributeJoin.getLhs(), attributeJoin ); // Only need to check the first level continue; } } - validateFetchOwners( selectedFromSet, sqmJoin, sqmTreat ); + validateFetchOwners( selectedFromSet, sqmTreat ); } - validateFetchOwners( selectedFromSet, sqmJoin, sqmJoin ); + validateFetchOwners( selectedFromSet, sqmJoin ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/TreatedSubclassSameTypeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/TreatedSubclassSameTypeTest.java index 349d08b335..e7d9f81900 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/TreatedSubclassSameTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/TreatedSubclassSameTypeTest.java @@ -61,11 +61,6 @@ public class TreatedSubclassSameTypeTest { executeQuery( scope, criteria -> criteria.from( MyEntity1.class ), true ); } - @Test - public void testJoin(SessionFactoryScope scope) { - executeQuery( scope, criteria -> criteria.from( MyEntity1.class ), false ); - } - @Test public void testJoinOnTreatedSubtype(SessionFactoryScope scope) { executeQuery( scope, criteria -> criteria.from( MySubEntity1.class ), true ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclass/JoinedSubclassTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclass/JoinedSubclassTest.java index 20d6f929cd..a1d54baa55 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclass/JoinedSubclassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclass/JoinedSubclassTest.java @@ -106,7 +106,7 @@ public class JoinedSubclassTest { Root root = criteria.from( Person.class ); - criteria.where( criteriaBuilder.gt( root.get( "salary" ), new BigDecimal( 100 ) ) ); + criteria.where( criteriaBuilder.gt( criteriaBuilder.treat( root, Employee.class ).get( "salary" ), new BigDecimal( 100 ) ) ); result = s.createQuery( criteria ).list(); // result = s.createCriteria( Person.class ) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/CorrelatedPluralJoinInheritanceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/CorrelatedPluralJoinInheritanceTest.java index beb1c7c23c..43e43c6102 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/CorrelatedPluralJoinInheritanceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/CorrelatedPluralJoinInheritanceTest.java @@ -99,12 +99,15 @@ public class CorrelatedPluralJoinInheritanceTest { } @Test - public void testImplicitTreat(EntityManagerFactoryScope scope) { + public void testExplicitTreat(EntityManagerFactoryScope scope) { scope.inTransaction( entityManager -> { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery criteriaQuery = cb.createQuery( ContinuousData.class ); final Root root = criteriaQuery.from( ContinuousData.class ); - criteriaQuery.where( createExistsPredicate( root, criteriaQuery, cb, "storedTags" ) ); + final Subquery subquery = criteriaQuery.subquery( String.class ); + final Root root2 = subquery.correlate( root ); + subquery.select( root2.get( "id" ) ).where( cb.treat( root2, StoredContinuousData.class ).join( "storedTags" ).get( "id" ).in( "a", "b" ) ); + criteriaQuery.where( cb.exists( subquery ) ); final List resultList = entityManager.createQuery( criteriaQuery ).getResultList(); assertThat( resultList ).hasSize( 1 ); } ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/inheritance/discriminator/DiscriminatorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/inheritance/discriminator/DiscriminatorTest.java index 541c3ef35d..d31a46680f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/inheritance/discriminator/DiscriminatorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/inheritance/discriminator/DiscriminatorTest.java @@ -177,7 +177,7 @@ public class DiscriminatorTest { CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); CriteriaQuery criteria = criteriaBuilder.createQuery( Person.class ); Root root = criteria.from( Person.class ); - criteria.where( criteriaBuilder.gt( root.get( "salary" ), new BigDecimal( 100 ) ) ); + criteria.where( criteriaBuilder.gt( criteriaBuilder.treat( root, Employee.class ).get( "salary" ), new BigDecimal( 100 ) ) ); result = s.createQuery( criteria ).list(); // result = s.createCriteria(Person.class) // .add( Property.forName( "salary").gt( new BigDecimal( 100) ) ) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/inheritance/discriminator/SimpleInheritanceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/inheritance/discriminator/SimpleInheritanceTest.java index d79b1d089f..ae11ad5aa9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/inheritance/discriminator/SimpleInheritanceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/inheritance/discriminator/SimpleInheritanceTest.java @@ -182,7 +182,7 @@ public class SimpleInheritanceTest { CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); CriteriaQuery criteria = criteriaBuilder.createQuery( Person.class ); Root root = criteria.from( Person.class ); - criteria.where( criteriaBuilder.gt( root.get( "salary" ), new BigDecimal( 100 ) ) ); + criteria.where( criteriaBuilder.gt( criteriaBuilder.treat( root, Employee.class ).get( "salary" ), new BigDecimal( 100 ) ) ); result = s.createQuery( criteria ).list(); // result = s.createCriteria( Person.class ) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaInheritanceJoinTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaInheritanceJoinTest.java index 84725fdc76..aeb4968586 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaInheritanceJoinTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaInheritanceJoinTest.java @@ -92,7 +92,7 @@ public class CriteriaInheritanceJoinTest { final CriteriaBuilder cb = session.getCriteriaBuilder(); final CriteriaQuery
cq = cb.createQuery( Address.class ); final Root
addressRoot = cq.from( Address.class ); - final Join join = addressRoot.join( "street" ); + final Join join = cb.treat( addressRoot, StreetAddress.class ).join( "street" ); cq.select( addressRoot ).where( cb.equal( join.get( "name" ), "Via Roma" ) ); final Address result = session.createQuery( cq ).getSingleResult(); assertThat( result ).isInstanceOf( StreetAddress.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass2/UnionSubclassTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass2/UnionSubclassTest.java index ad6ff9c1bf..50dfd3519c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass2/UnionSubclassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass2/UnionSubclassTest.java @@ -160,7 +160,7 @@ public class UnionSubclassTest { CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); CriteriaQuery criteria = criteriaBuilder.createQuery( Person.class ); Root root = criteria.from( Person.class ); - criteria.where( criteriaBuilder.gt( root.get( "salary" ), new BigDecimal( 100 ) ) ); + criteria.where( criteriaBuilder.gt( criteriaBuilder.treat( root, Employee.class ).get( "salary" ), new BigDecimal( 100 ) ) ); result = s.createQuery( criteria ).list(); diff --git a/migration-guide.adoc b/migration-guide.adoc index 785f779833..280abe313a 100644 --- a/migration-guide.adoc +++ b/migration-guide.adoc @@ -376,6 +376,13 @@ In Hibernate 7, the configuration property `hibernate.jdbc.batch_size` now has n Automatic batching may be enabled by explicitly calling `setJdbcBatchSize()`. However, the preferred approach is to explicitly batch operations via `insertMultiple()`, `updateMultiple()`, or `deleteMultiple()`. +[[criteria-implicit-treat]] +== Criteria API and inheritance subtypes attributes + +It was previously possible to use the string version of the `jakarta.persistence.criteria.Path#get` and `jakarta.persistence.criteria.From#join` methods with names of attributes defined in an inheritance subtype of the type represented by the path expression. This was handled internally by implicitly treating the path as the subtype which defines said attribute. Since Hibernate 7.0, aligning with the JPA specification, the Criteria API will no longer allow retrieving subtype attributes this way, and it's going to require an explicit `jakarta.persistence.criteria.CriteriaBuilder#treat` to be called on the path first to downcast it to the subtype which defines the attribute. + +Implicit treats are still going to be applied when an HQL query dereferences a path belonging to an inheritance subtype. + [[hbm-transform]] == hbm.xml Transformation diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java index 8725d0c1e8..2daf89af83 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java @@ -62,7 +62,6 @@ import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; @@ -973,14 +972,14 @@ public abstract class MockSessionFactory } @Override - public SqmPathSource findSubPathSource(String name, JpaMetamodel metamodel) { + public SqmPathSource findSubPathSource(String name, boolean includeSubtypes) { switch (name) { case EntityIdentifierMapping.ID_ROLE_NAME: return getIdentifierDescriptor(); case "{version}": return findVersionAttribute(); } - final SqmPathSource source = super.findSubPathSource(name, metamodel); + final SqmPathSource source = super.findSubPathSource(name, includeSubtypes); if ( source != null ) { return source; }