diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java index 483de248a9..759079e69e 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java @@ -77,7 +77,7 @@ public enum AccessType { return null; } for ( AccessType accessType : AccessType.values() ) { - if ( accessType.getExternalName().equalsIgnoreCase( externalName ) ) { + if ( accessType.getExternalName().equals( externalName ) ) { return accessType; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/DiscriminatorSqmPath.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/DiscriminatorSqmPath.java index 65793da92d..db891935ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/DiscriminatorSqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/DiscriminatorSqmPath.java @@ -30,13 +30,39 @@ public interface DiscriminatorSqmPath extends SqmPath { throw new IllegalStateException( "Discriminator cannot be de-referenced" ); } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override default SqmTreatedPath treatAs(Class treatJavaType) throws PathException { throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" ); } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override default SqmTreatedPath treatAs(EntityDomainType treatTarget) throws PathException { throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" ); } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + default SqmTreatedPath treatAs(Class treatJavaType, String alias) throws PathException { + throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" ); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + default SqmTreatedPath treatAs(EntityDomainType treatTarget, String alias) throws PathException { + throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" ); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + default SqmTreatedPath treatAs(Class treatJavaType, String alias, boolean fetch) throws PathException { + throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" ); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + default SqmTreatedPath treatAs(EntityDomainType treatTarget, String alias, boolean fetch) throws PathException { + throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyDiscriminatorSqmPath.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyDiscriminatorSqmPath.java index abbd84ff6c..e65d024cb8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyDiscriminatorSqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyDiscriminatorSqmPath.java @@ -47,5 +47,4 @@ public class AnyDiscriminatorSqmPath extends AbstractSqmPath implements Di public AnyDiscriminatorSqmPathSource getExpressible() { return (AnyDiscriminatorSqmPathSource) getNodeType(); } - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index ce568734bc..d23eb9a268 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -78,6 +78,7 @@ import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SetOperator; import org.hibernate.query.sqm.SqmExpressible; import org.hibernate.query.sqm.SqmPathSource; +import org.hibernate.query.sqm.SqmQuerySource; import org.hibernate.query.sqm.TemporalUnit; import org.hibernate.query.sqm.TrimSpec; import org.hibernate.query.sqm.UnaryArithmeticOperator; @@ -572,7 +573,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, @Override public SqmRoot treat(Root root, Class type) { //noinspection unchecked - return (SqmTreatedRoot) ( (SqmRoot) root ).treatAs( type ); + return (SqmTreatedRoot) ( (SqmRoot) root ).treatAs( type ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmAttributeJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmAttributeJoin.java index 28fe06d2ff..5bb79c771c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmAttributeJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmAttributeJoin.java @@ -36,6 +36,7 @@ public abstract class AbstractSqmAttributeJoin private boolean fetched; + @SuppressWarnings({ "rawtypes", "unchecked" }) public AbstractSqmAttributeJoin( SqmFrom lhs, SqmJoinable joinedNavigable, @@ -43,6 +44,7 @@ public abstract class AbstractSqmAttributeJoin SqmJoinType joinType, boolean fetched, NodeBuilder nodeBuilder) { + //noinspection StringEquality this( lhs, joinedNavigable.createNavigablePath( lhs, alias ), @@ -54,6 +56,7 @@ public abstract class AbstractSqmAttributeJoin ); } + @SuppressWarnings("rawtypes") protected AbstractSqmAttributeJoin( SqmFrom lhs, NavigablePath navigablePath, @@ -158,5 +161,11 @@ public abstract class AbstractSqmAttributeJoin @Override public abstract SqmTreatedAttributeJoin treatAs(EntityDomainType treatTarget, String alias); + @Override + public abstract SqmTreatedAttributeJoin treatAs(Class treatJavaType, String alias, boolean fetched); + + @Override + public abstract SqmTreatedAttributeJoin treatAs(EntityDomainType treatTarget, String alias, boolean fetched); + } 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 b25c661d75..f2141bd2fa 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 @@ -844,6 +844,36 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements ); } + @Override + public SqmTreatedFrom treatAs(Class treatJavaType) { + return (SqmTreatedFrom) super.treatAs( treatJavaType ); + } + + @Override + public SqmTreatedFrom treatAs(EntityDomainType treatTarget) { + return (SqmTreatedFrom) super.treatAs( treatTarget ); + } + + @Override + public SqmTreatedFrom treatAs(Class treatJavaType, String alias) { + return (SqmTreatedFrom) super.treatAs( treatJavaType, alias ); + } + + @Override + public SqmTreatedFrom treatAs(EntityDomainType treatTarget, String alias) { + return (SqmTreatedFrom) super.treatAs( treatTarget, alias ); + } + + @Override + public SqmTreatedFrom treatAs(Class treatJavaType, String alias, boolean fetch) { + return (SqmTreatedFrom) super.treatAs( treatJavaType, alias, fetch ); + } + + @Override + public SqmTreatedFrom treatAs(EntityDomainType treatTarget, String alias, boolean fetch) { + return (SqmTreatedFrom) super.treatAs( treatTarget, alias, fetch ); + } + @Override public void appendHqlString(StringBuilder sb) { if ( alias == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java index 2e7124287b..f13848ee47 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java @@ -94,6 +94,12 @@ public abstract class AbstractSqmJoin extends AbstractSqmFrom implem @Override public abstract SqmTreatedJoin treatAs(EntityDomainType treatTarget, String alias); + @Override + public abstract SqmTreatedJoin treatAs(Class treatJavaType, String alias, boolean fetched); + + @Override + public abstract SqmTreatedJoin treatAs(EntityDomainType treatTarget, String alias, boolean fetched); + @Override public SqmFrom getLhs() { //noinspection unchecked 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 0e6dd260d2..6d7667d68a 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 @@ -237,6 +237,36 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem return path; } + @Override + public SqmTreatedPath treatAs(Class treatJavaType) { + return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) ); + } + + @Override + public SqmTreatedPath treatAs(EntityDomainType treatTarget) { + return getTreatedPath( treatTarget ); + } + + @Override + public SqmTreatedPath treatAs(Class treatJavaType, String alias) { + return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) ); + } + + @Override + public SqmTreatedPath treatAs(EntityDomainType treatTarget, String alias) { + return getTreatedPath( treatTarget ); + } + + @Override + public SqmTreatedPath treatAs(Class treatJavaType, String alias, boolean fetch) { + return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) ); + } + + @Override + public SqmTreatedPath treatAs(EntityDomainType treatTarget, String alias, boolean fetch) { + return null; + } + /** * Utility that checks if this path's parent navigable path is compatible with the specified SQM parent, * and if not creates a copy of the navigable path with the correct parent. diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/NonAggregatedCompositeSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/NonAggregatedCompositeSimplePath.java index 38e40b5262..38cc933845 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/NonAggregatedCompositeSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/NonAggregatedCompositeSimplePath.java @@ -58,9 +58,33 @@ public class NonAggregatedCompositeSimplePath extends SqmEntityValuedSimplePa return walker.visitNonAggregatedCompositeValuedPath( this ); } + @Override + public SqmTreatedSimplePath treatAs(Class treatJavaType) throws PathException { + throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" ); + } @Override - public SqmTreatedPath treatAs(EntityDomainType treatTarget) throws PathException { + public SqmTreatedSimplePath treatAs(EntityDomainType treatTarget) throws PathException { + throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" ); + } + + @Override + public SqmTreatedSimplePath treatAs(Class treatJavaType, String alias) { + throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" ); + } + + @Override + public SqmTreatedSimplePath treatAs(EntityDomainType treatTarget, String alias) { + throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" ); + } + + @Override + public SqmTreatedPath treatAs(Class treatJavaType, String alias, boolean fetch) { + throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" ); + } + + @Override + public SqmTreatedPath treatAs(EntityDomainType treatTarget, String alias, boolean fetch) { throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmDerivedRoot.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmDerivedRoot.java index a4c6596ec2..158b9a3a4a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmDerivedRoot.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmDerivedRoot.java @@ -117,12 +117,12 @@ public class SqmDerivedRoot extends SqmRoot implements JpaDerivedRoot { } @Override - public SqmTreatedFrom treatAs(Class treatJavaType, String alias) { + public SqmTreatedRoot treatAs(Class treatJavaType, String alias) { throw new UnsupportedOperationException( "Derived roots can not be treated" ); } @Override - public SqmTreatedFrom treatAs(EntityDomainType treatTarget, String alias) { + public SqmTreatedRoot treatAs(EntityDomainType treatTarget, String alias) { throw new UnsupportedOperationException( "Derived roots can not be treated" ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapJoin.java index 773cc29a04..1e364929aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapJoin.java @@ -185,6 +185,20 @@ public class SqmMapJoin return treat; } + @Override + public SqmTreatedMapJoin treatAs(Class treatJavaType, String alias, boolean fetched) { + return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias, fetched ); + } + + @Override + public SqmTreatedMapJoin treatAs(EntityDomainType treatTarget, String alias, boolean fetched) { + final SqmTreatedMapJoin treat = findTreat( treatTarget, alias ); + if ( treat == null ) { + return addTreat( new SqmTreatedMapJoin<>( this, treatTarget, alias ) ); + } + return treat; + } + @Override public SqmMapJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmMapJoin<>( 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 f5fcf01f6e..f57d326461 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 @@ -125,6 +125,14 @@ public interface SqmPath extends SqmExpression, SemanticPathPart, JpaPath< @Override SqmTreatedPath treatAs(EntityDomainType treatTarget); + SqmTreatedPath treatAs(Class treatJavaType, String alias); + + SqmTreatedPath treatAs(EntityDomainType treatTarget, String alias); + + SqmTreatedPath treatAs(Class treatJavaType, String alias, boolean fetch); + + SqmTreatedPath treatAs(EntityDomainType treatTarget, String alias, boolean fetch); + default SqmRoot findRoot() { final SqmPath lhs = getLhs(); if ( lhs != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPluralPartJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPluralPartJoin.java index 54b417a139..7a5aeb5d15 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPluralPartJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPluralPartJoin.java @@ -10,7 +10,6 @@ import java.util.Locale; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.PersistentAttribute; -import org.hibernate.spi.NavigablePath; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SqmPathSource; @@ -19,6 +18,7 @@ import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.from.SqmFrom; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; +import org.hibernate.spi.NavigablePath; /** * @author Christian Beikov @@ -99,30 +99,50 @@ public class SqmPluralPartJoin extends AbstractSqmJoin { public X accept(SemanticQueryWalker walker) { return walker.visitPluralPartJoin( this ); } -// -// @Override -// public SqmTreatedPluralPartJoin treatAs(Class treatJavaType) { -// return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) ); -// } -// -// @Override -// public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget) { -// return treatAs( treatTarget, null ); -// } -// -// @Override -// public SqmTreatedPluralPartJoin treatAs(Class treatJavaType, String alias) { -// return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias ); -// } -// -// @Override -// public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget, String alias) { -// final SqmTreatedPluralPartJoin treat = findTreat( treatTarget, alias ); -// if ( treat == null ) { -// return addTreat( new SqmTreatedPluralPartJoin<>( this, treatTarget, alias ) ); -// } -// return treat; -// } + + @SuppressWarnings("unchecked") + @Override + public SqmTreatedPluralPartJoin treatAs(Class treatJavaType) { + return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) ); + } + + @SuppressWarnings("unchecked") + @Override + public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget) { + return treatAs( treatTarget, null ); + } + + @SuppressWarnings("unchecked") + @Override + public SqmTreatedPluralPartJoin treatAs(Class treatJavaType, String alias) { + return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias ); + } + + @SuppressWarnings("unchecked") + @Override + public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget, String alias) { + final SqmTreatedPluralPartJoin treat = findTreat( treatTarget, alias ); + if ( treat == null ) { + return addTreat( new SqmTreatedPluralPartJoin( this, treatTarget, alias ) ); + } + return treat; + } + + @SuppressWarnings("unchecked") + @Override + public SqmTreatedPluralPartJoin treatAs(Class treatJavaType, String alias, boolean fetch) { + return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias, fetch ); + } + + @SuppressWarnings("unchecked") + @Override + public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget, String alias, boolean fetch) { + final SqmTreatedPluralPartJoin treat = findTreat( treatTarget, alias ); + if ( treat == null ) { + return addTreat( new SqmTreatedPluralPartJoin( this, treatTarget, alias ) ); + } + return treat; + } @Override @@ -130,26 +150,6 @@ public class SqmPluralPartJoin extends AbstractSqmJoin { return null; } - @Override - public SqmTreatedPluralPartJoin treatAs(Class treatJavaType) { - return null; - } - - @Override - public SqmTreatedJoin treatAs(EntityDomainType treatTarget) { - return null; - } - - @Override - public SqmTreatedJoin treatAs(Class treatJavaType, String alias) { - return null; - } - - @Override - public SqmTreatedJoin treatAs(EntityDomainType treatTarget, String alias) { - return null; - } - @Override public SqmCorrelatedPluralPartJoin createCorrelation() { return new SqmCorrelatedPluralPartJoin<>( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedFrom.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedFrom.java index 18ebeff7e9..341b657bbe 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedFrom.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedFrom.java @@ -27,6 +27,12 @@ public interface SqmTreatedFrom extends SqmFrom, SqmTrea @Override SqmTreatedFrom treatAs(EntityDomainType treatTarget, String alias); + @Override + SqmTreatedFrom treatAs(Class treatJavaType, String alias, boolean fetch); + + @Override + SqmTreatedFrom treatAs(EntityDomainType treatTarget, String alias, boolean fetch); + @Override SqmTreatedFrom copy(SqmCopyContext context); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedMapJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedMapJoin.java index aac04b30a2..8c0bddb9a5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedMapJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedMapJoin.java @@ -27,6 +27,7 @@ public class SqmTreatedMapJoin extends SqmMapJoin private final SqmMapJoin wrappedPath; private final TreatableDomainType treatTarget; + @SuppressWarnings({ "rawtypes" }) public SqmTreatedMapJoin( SqmMapJoin wrappedPath, TreatableDomainType treatTarget, @@ -34,12 +35,12 @@ public class SqmTreatedMapJoin extends SqmMapJoin this( wrappedPath, treatTarget, alias, false ); } + @SuppressWarnings({ "rawtypes", "unchecked" }) public SqmTreatedMapJoin( SqmMapJoin wrappedPath, TreatableDomainType treatTarget, String alias, boolean fetched) { - //noinspection unchecked super( wrappedPath.getLhs(), wrappedPath.getNavigablePath() diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedPath.java index bc525ad690..d034ba1592 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedPath.java @@ -27,4 +27,5 @@ public interface SqmTreatedPath extends JpaTreatedPath, Sqm @Override SqmTreatedPath treatAs(EntityDomainType treatTarget); + } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedPluralPartJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedPluralPartJoin.java index 1cee12c6df..5bdf5d4a20 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedPluralPartJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedPluralPartJoin.java @@ -9,28 +9,28 @@ package org.hibernate.query.sqm.tree.domain; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.SqmCopyContext; -import org.hibernate.query.sqm.tree.from.SqmFrom; import org.hibernate.spi.NavigablePath; /** * @author Steve Ebersole */ -public class SqmTreatedPluralPartJoin extends SqmPluralPartJoin implements SqmTreatedJoin { - private final SqmPluralPartJoin wrappedPath; - private final EntityDomainType treatTarget; +@SuppressWarnings("rawtypes") +public class SqmTreatedPluralPartJoin extends SqmPluralPartJoin implements SqmTreatedJoin { + private final SqmPluralPartJoin wrappedPath; + private final EntityDomainType treatTarget; public SqmTreatedPluralPartJoin( - SqmPluralPartJoin wrappedPath, - EntityDomainType treatTarget, + SqmPluralPartJoin wrappedPath, + EntityDomainType treatTarget, String alias) { //noinspection unchecked super( - (SqmFrom) wrappedPath.getLhs(), + wrappedPath.getLhs(), wrappedPath.getNavigablePath().treatAs( treatTarget.getHibernateEntityName(), alias ), - (SqmPathSource) wrappedPath.getReferencedPathSource(), + wrappedPath.getReferencedPathSource(), alias, wrappedPath.getSqmJoinType(), wrappedPath.nodeBuilder() @@ -41,14 +41,14 @@ public class SqmTreatedPluralPartJoin extends SqmPluralPartJoi private SqmTreatedPluralPartJoin( NavigablePath navigablePath, - SqmPluralPartJoin wrappedPath, - EntityDomainType treatTarget, + SqmPluralPartJoin wrappedPath, + EntityDomainType treatTarget, String alias) { //noinspection unchecked super( - (SqmFrom) wrappedPath.getLhs(), + wrappedPath.getLhs(), navigablePath, - (SqmPathSource) wrappedPath.getReferencedPathSource(), + wrappedPath.getReferencedPathSource(), alias, wrappedPath.getSqmJoinType(), wrappedPath.nodeBuilder() @@ -58,14 +58,14 @@ public class SqmTreatedPluralPartJoin extends SqmPluralPartJoi } @Override - public SqmTreatedPluralPartJoin copy(SqmCopyContext context) { - final SqmTreatedPluralPartJoin existing = context.getCopy( this ); + public SqmTreatedPluralPartJoin copy(SqmCopyContext context) { + final SqmTreatedPluralPartJoin existing = context.getCopy( this ); if ( existing != null ) { return existing; } - final SqmTreatedPluralPartJoin path = context.registerCopy( + final SqmTreatedPluralPartJoin path = context.registerCopy( this, - new SqmTreatedPluralPartJoin<>( + new SqmTreatedPluralPartJoin( getNavigablePath(), wrappedPath.copy( context ), treatTarget, @@ -77,22 +77,22 @@ public class SqmTreatedPluralPartJoin extends SqmPluralPartJoi } @Override - public SqmPluralPartJoin getWrappedPath() { + public SqmPluralPartJoin getWrappedPath() { return wrappedPath; } @Override - public EntityDomainType getTreatTarget() { + public EntityDomainType getTreatTarget() { return treatTarget; } @Override - public SqmPathSource getNodeType() { + public SqmPathSource getNodeType() { return treatTarget; } @Override - public SqmPathSource getReferencedPathSource() { + public SqmPathSource getReferencedPathSource() { return treatTarget; } @@ -102,23 +102,39 @@ public class SqmTreatedPluralPartJoin extends SqmPluralPartJoi } @Override - public SqmTreatedPluralPartJoin treatAs(Class treatJavaType) { + public SqmTreatedPluralPartJoin treatAs(Class treatJavaType) { + //noinspection unchecked return super.treatAs( treatJavaType ); } @Override - public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget) { - return (SqmTreatedPluralPartJoin) super.treatAs( treatTarget ); + public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget) { + //noinspection unchecked + return (SqmTreatedPluralPartJoin) super.treatAs( treatTarget ); } @Override - public SqmTreatedPluralPartJoin treatAs(Class treatJavaType, String alias) { - return (SqmTreatedPluralPartJoin) super.treatAs( treatJavaType, alias ); + public SqmTreatedPluralPartJoin treatAs(Class treatJavaType, String alias) { + //noinspection unchecked + return (SqmTreatedPluralPartJoin) super.treatAs( treatJavaType, alias ); } @Override - public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget, String alias) { - return (SqmTreatedPluralPartJoin) super.treatAs( treatTarget, alias ); + public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget, String alias) { + //noinspection unchecked + return (SqmTreatedPluralPartJoin) super.treatAs( treatTarget, alias ); + } + + @Override + public SqmTreatedPluralPartJoin treatAs(Class treatJavaType, String alias, boolean fetch) { + //noinspection unchecked + return (SqmTreatedPluralPartJoin) super.treatAs( treatJavaType, alias, fetch ); + } + + @Override + public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget, String alias, boolean fetch) { + //noinspection unchecked + return (SqmTreatedPluralPartJoin) super.treatAs( treatTarget, alias, fetch ); } 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 e053642550..a92edc90c4 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 @@ -17,14 +17,15 @@ import org.hibernate.spi.NavigablePath; /** * @author Steve Ebersole */ -public class SqmTreatedRoot extends SqmRoot implements SqmTreatedFrom { - private final SqmRoot wrappedPath; - private final EntityDomainType treatTarget; +@SuppressWarnings("rawtypes") +public class SqmTreatedRoot extends SqmRoot implements SqmTreatedFrom { + private final SqmRoot wrappedPath; + private final EntityDomainType treatTarget; @SuppressWarnings({ "unchecked", "rawtypes" }) public SqmTreatedRoot( - SqmRoot wrappedPath, - EntityDomainType treatTarget) { + SqmRoot wrappedPath, + EntityDomainType treatTarget) { super( wrappedPath.getNavigablePath().treatAs( treatTarget.getHibernateEntityName() @@ -40,8 +41,8 @@ public class SqmTreatedRoot extends SqmRoot implements SqmTre @SuppressWarnings({ "unchecked", "rawtypes" }) private SqmTreatedRoot( NavigablePath navigablePath, - SqmRoot wrappedPath, - EntityDomainType treatTarget) { + SqmRoot wrappedPath, + EntityDomainType treatTarget) { super( navigablePath, (EntityDomainType) wrappedPath.getReferencedPathSource(), @@ -53,14 +54,14 @@ public class SqmTreatedRoot extends SqmRoot implements SqmTre } @Override - public SqmTreatedRoot copy(SqmCopyContext context) { - final SqmTreatedRoot existing = context.getCopy( this ); + public SqmTreatedRoot copy(SqmCopyContext context) { + final SqmTreatedRoot existing = context.getCopy( this ); if ( existing != null ) { return existing; } - final SqmTreatedRoot path = context.registerCopy( + final SqmTreatedRoot path = context.registerCopy( this, - new SqmTreatedRoot<>( + new SqmTreatedRoot( getNavigablePath(), wrappedPath.copy( context ), treatTarget @@ -71,27 +72,27 @@ public class SqmTreatedRoot extends SqmRoot implements SqmTre } @Override - public EntityDomainType getTreatTarget() { + public EntityDomainType getTreatTarget() { return treatTarget; } @Override - public EntityDomainType getManagedType() { + public EntityDomainType getManagedType() { return getTreatTarget(); } @Override - public SqmPath getWrappedPath() { + public SqmPath getWrappedPath() { return wrappedPath; } @Override - public SqmPathSource getNodeType() { + public SqmPathSource getNodeType() { return treatTarget; } @Override - public EntityDomainType getReferencedPathSource() { + public EntityDomainType getReferencedPathSource() { return getTreatTarget(); } @@ -100,8 +101,9 @@ public class SqmTreatedRoot extends SqmRoot implements SqmTre return wrappedPath.getLhs(); } + @SuppressWarnings("unchecked") @Override - public X accept(SemanticQueryWalker walker) { + public Object accept(SemanticQueryWalker walker) { return walker.visitTreatedPath( this ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCrossJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCrossJoin.java index a4f5c1f96c..e38ca31807 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCrossJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCrossJoin.java @@ -17,6 +17,7 @@ import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.domain.AbstractSqmFrom; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedCrossJoin; import org.hibernate.query.sqm.tree.domain.SqmTreatedCrossJoin; +import org.hibernate.query.sqm.tree.domain.SqmTreatedFrom; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.predicate.SqmPredicateCollection; import org.hibernate.query.sqm.tree.predicate.SqmWhereClause; @@ -189,6 +190,17 @@ public class SqmCrossJoin extends AbstractSqmFrom implements JpaCrossJo public SqmTreatedCrossJoin treatAs(EntityDomainType treatTarget, String alias) { throw new UnsupportedOperationException( "Cross join treats can not be aliased" ); } + + @Override + public SqmTreatedFrom treatAs(Class treatJavaType, String alias, boolean fetch) { + return null; + } + + @Override + public SqmTreatedFrom treatAs(EntityDomainType treatTarget, String alias, boolean fetch) { + return null; + } + @SuppressWarnings("unchecked") @Override public SqmTreatedCrossJoin treatAs(Class treatAsType) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCteJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCteJoin.java index 62719bfead..5b29a091a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCteJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCteJoin.java @@ -137,6 +137,16 @@ public class SqmCteJoin extends AbstractSqmJoin { throw new UnsupportedOperationException( "CTE joins can not be treated" ); } + @Override + public SqmTreatedJoin treatAs(Class treatJavaType, String alias, boolean fetched) { + throw new UnsupportedOperationException( "CTE joins can not be treated" ); + } + + @Override + public SqmTreatedJoin treatAs(EntityDomainType treatTarget, String alias, boolean fetched) { + throw new UnsupportedOperationException( "CTE joins can not be treated" ); + } + @Override public SqmFrom getParent() { return getCorrelationParent(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmDerivedJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmDerivedJoin.java index 15358365bb..afcb944e0e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmDerivedJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmDerivedJoin.java @@ -192,6 +192,16 @@ public class SqmDerivedJoin extends AbstractSqmJoin implements JpaDeriv throw new UnsupportedOperationException( "Derived joins can not be treated" ); } + @Override + public SqmTreatedJoin treatAs(Class treatJavaType, String alias, boolean fetched) { + throw new UnsupportedOperationException( "Derived joins can not be treated" ); + } + + @Override + public SqmTreatedJoin treatAs(EntityDomainType treatTarget, String alias, boolean fetched) { + throw new UnsupportedOperationException( "Derived joins can not be treated" ); + } + @Override public PersistentAttribute getAttribute() { // none diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java index 8c57914dde..102adb9996 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java @@ -194,6 +194,16 @@ public class SqmEntityJoin extends AbstractSqmJoin implements SqmSingu throw new UnsupportedOperationException( "Entity join treats can not be aliased" ); } + @Override + public SqmTreatedEntityJoin treatAs(Class treatJavaType, String alias, boolean fetched) { + throw new UnsupportedOperationException( "Entity join treats can not be aliased" ); + } + + @Override + public SqmTreatedEntityJoin treatAs(EntityDomainType treatTarget, String alias, boolean fetched) { + throw new UnsupportedOperationException( "Entity join treats can not be aliased" ); + } + @Override public PersistentAttribute getAttribute() { // there is no attribute diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFrom.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFrom.java index f040621ad9..fc2ae0baf5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFrom.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFrom.java @@ -17,7 +17,6 @@ import jakarta.persistence.metamodel.SetAttribute; import jakarta.persistence.metamodel.SingularAttribute; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.query.criteria.JpaEntityJoin; import org.hibernate.query.criteria.JpaFrom; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.SqmCopyContext; @@ -82,8 +81,10 @@ public interface SqmFrom extends SqmVisitableNode, SqmPath, JpaFrom SqmTreatedFrom treatAs(EntityDomainType treatTarget); + @Override SqmTreatedFrom treatAs(Class treatJavaType, String alias); + @Override SqmTreatedFrom treatAs(EntityDomainType treatTarget, String alias); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmRoot.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmRoot.java index becf70cba8..c5f7f28776 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmRoot.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmRoot.java @@ -11,7 +11,9 @@ import java.util.List; import org.hibernate.Internal; import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.query.sqm.TreatException; import org.hibernate.query.sqm.tree.domain.SqmTreatedFrom; +import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; import org.hibernate.spi.NavigablePath; import org.hibernate.query.PathException; import org.hibernate.query.criteria.JpaRoot; @@ -206,14 +208,28 @@ public class SqmRoot extends AbstractSqmFrom implements JpaRoot { return treat; } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - public SqmTreatedFrom treatAs(Class treatJavaType, String alias) { + public SqmTreatedRoot treatAs(Class treatJavaType, String alias) { throw new UnsupportedOperationException( "Root treats can not be aliased" ); } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - public SqmTreatedFrom treatAs(EntityDomainType treatTarget, String alias) { + public SqmTreatedRoot treatAs(EntityDomainType treatTarget, String alias) { throw new UnsupportedOperationException( "Root treats can not be aliased" ); } + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public SqmTreatedRoot treatAs(Class treatJavaType, String alias, boolean fetch) { + throw new TreatException( "Root paths cannot be aliased, nor fetched - " + getNavigablePath().getFullPath() ); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public SqmTreatedRoot treatAs(EntityDomainType treatTarget, String alias, boolean fetch) { + throw new TreatException( "Root paths cannot be aliased, nor fetched - " + getNavigablePath().getFullPath() ); + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java index 00c086d9dc..b47853584f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java @@ -26,6 +26,8 @@ import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.cte.SqmCteStatement; import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter; import org.hibernate.query.sqm.tree.expression.SqmParameter; +import org.hibernate.query.sqm.tree.expression.SqmStar; +import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter; import org.hibernate.query.sqm.tree.from.SqmFromClause; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.from.SqmRoot; @@ -517,6 +519,8 @@ public class SqmSelectStatement extends AbstractSqmSelectQuery implements query.select( nodeBuilder().count() ); return query; } + + querySpec.getSelectClause().setSelection( (SqmSelectableNode) nodeBuilder.tuple( subSelections ) ); } private void aliasSelections(SqmQueryPart queryPart) {