HHH-17377 - Migrate to JPA 3.2

https://hibernate.atlassian.net/browse/HHH-17377

rebase from main
This commit is contained in:
Steve Ebersole 2023-11-16 13:31:58 -06:00
parent 0340375081
commit 11d83b5af9
25 changed files with 335 additions and 99 deletions

View File

@ -77,7 +77,7 @@ public enum AccessType {
return null; return null;
} }
for ( AccessType accessType : AccessType.values() ) { for ( AccessType accessType : AccessType.values() ) {
if ( accessType.getExternalName().equalsIgnoreCase( externalName ) ) { if ( accessType.getExternalName().equals( externalName ) ) {
return accessType; return accessType;
} }
} }

View File

@ -30,13 +30,39 @@ public interface DiscriminatorSqmPath<T> extends SqmPath<T> {
throw new IllegalStateException( "Discriminator cannot be de-referenced" ); throw new IllegalStateException( "Discriminator cannot be de-referenced" );
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override @Override
default SqmTreatedPath treatAs(Class treatJavaType) throws PathException { default SqmTreatedPath treatAs(Class treatJavaType) throws PathException {
throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" ); throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" );
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override @Override
default SqmTreatedPath treatAs(EntityDomainType treatTarget) throws PathException { default SqmTreatedPath treatAs(EntityDomainType treatTarget) throws PathException {
throw new UnsupportedMappingException( "Cannot apply TREAT operator to discriminator path" ); 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" );
}
} }

View File

@ -47,5 +47,4 @@ public class AnyDiscriminatorSqmPath<T> extends AbstractSqmPath<T> implements Di
public AnyDiscriminatorSqmPathSource<T> getExpressible() { public AnyDiscriminatorSqmPathSource<T> getExpressible() {
return (AnyDiscriminatorSqmPathSource<T>) getNodeType(); return (AnyDiscriminatorSqmPathSource<T>) getNodeType();
} }
} }

View File

@ -78,6 +78,7 @@ import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SetOperator; import org.hibernate.query.sqm.SetOperator;
import org.hibernate.query.sqm.SqmExpressible; import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.SqmQuerySource;
import org.hibernate.query.sqm.TemporalUnit; import org.hibernate.query.sqm.TemporalUnit;
import org.hibernate.query.sqm.TrimSpec; import org.hibernate.query.sqm.TrimSpec;
import org.hibernate.query.sqm.UnaryArithmeticOperator; import org.hibernate.query.sqm.UnaryArithmeticOperator;
@ -572,7 +573,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
@Override @Override
public <X, T extends X> SqmRoot<T> treat(Root<X> root, Class<T> type) { public <X, T extends X> SqmRoot<T> treat(Root<X> root, Class<T> type) {
//noinspection unchecked //noinspection unchecked
return (SqmTreatedRoot<X,T>) ( (SqmRoot<X>) root ).treatAs( type ); return (SqmTreatedRoot) ( (SqmRoot<X>) root ).treatAs( type );
} }
@Override @Override

View File

@ -36,6 +36,7 @@ public abstract class AbstractSqmAttributeJoin<L, R>
private boolean fetched; private boolean fetched;
@SuppressWarnings({ "rawtypes", "unchecked" })
public AbstractSqmAttributeJoin( public AbstractSqmAttributeJoin(
SqmFrom<?, L> lhs, SqmFrom<?, L> lhs,
SqmJoinable joinedNavigable, SqmJoinable joinedNavigable,
@ -43,6 +44,7 @@ public abstract class AbstractSqmAttributeJoin<L, R>
SqmJoinType joinType, SqmJoinType joinType,
boolean fetched, boolean fetched,
NodeBuilder nodeBuilder) { NodeBuilder nodeBuilder) {
//noinspection StringEquality
this( this(
lhs, lhs,
joinedNavigable.createNavigablePath( lhs, alias ), joinedNavigable.createNavigablePath( lhs, alias ),
@ -54,6 +56,7 @@ public abstract class AbstractSqmAttributeJoin<L, R>
); );
} }
@SuppressWarnings("rawtypes")
protected AbstractSqmAttributeJoin( protected AbstractSqmAttributeJoin(
SqmFrom<?, L> lhs, SqmFrom<?, L> lhs,
NavigablePath navigablePath, NavigablePath navigablePath,
@ -158,5 +161,11 @@ public abstract class AbstractSqmAttributeJoin<L, R>
@Override @Override
public abstract <S extends R> SqmTreatedAttributeJoin<L, R, S> treatAs(EntityDomainType<S> treatTarget, String alias); public abstract <S extends R> SqmTreatedAttributeJoin<L, R, S> treatAs(EntityDomainType<S> treatTarget, String alias);
@Override
public abstract <S extends R> SqmTreatedAttributeJoin<L, R, S> treatAs(Class<S> treatJavaType, String alias, boolean fetched);
@Override
public abstract <S extends R> SqmTreatedAttributeJoin<L, R, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetched);
} }

View File

@ -844,6 +844,36 @@ public abstract class AbstractSqmFrom<O,T> extends AbstractSqmPath<T> implements
); );
} }
@Override
public <S extends T> SqmTreatedFrom<O,T,S> treatAs(Class<S> treatJavaType) {
return (SqmTreatedFrom<O,T,S>) super.treatAs( treatJavaType );
}
@Override
public <S extends T> SqmTreatedFrom<O,T,S> treatAs(EntityDomainType<S> treatTarget) {
return (SqmTreatedFrom<O,T,S>) super.treatAs( treatTarget );
}
@Override
public <S extends T> SqmTreatedFrom<O,T,S> treatAs(Class<S> treatJavaType, String alias) {
return (SqmTreatedFrom<O,T,S>) super.treatAs( treatJavaType, alias );
}
@Override
public <S extends T> SqmTreatedFrom<O,T,S> treatAs(EntityDomainType<S> treatTarget, String alias) {
return (SqmTreatedFrom<O,T,S>) super.treatAs( treatTarget, alias );
}
@Override
public <S extends T> SqmTreatedFrom<O,T,S> treatAs(Class<S> treatJavaType, String alias, boolean fetch) {
return (SqmTreatedFrom<O,T,S>) super.treatAs( treatJavaType, alias, fetch );
}
@Override
public <S extends T> SqmTreatedFrom<O,T,S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch) {
return (SqmTreatedFrom<O,T,S>) super.treatAs( treatTarget, alias, fetch );
}
@Override @Override
public void appendHqlString(StringBuilder sb) { public void appendHqlString(StringBuilder sb) {
if ( alias == null ) { if ( alias == null ) {

View File

@ -94,6 +94,12 @@ public abstract class AbstractSqmJoin<L, R> extends AbstractSqmFrom<L, R> implem
@Override @Override
public abstract <S extends R> SqmTreatedJoin<L, R, S> treatAs(EntityDomainType<S> treatTarget, String alias); public abstract <S extends R> SqmTreatedJoin<L, R, S> treatAs(EntityDomainType<S> treatTarget, String alias);
@Override
public abstract <S extends R> SqmTreatedJoin<L, R, S> treatAs(Class<S> treatJavaType, String alias, boolean fetched);
@Override
public abstract <S extends R> SqmTreatedJoin<L, R, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetched);
@Override @Override
public SqmFrom<?, L> getLhs() { public SqmFrom<?, L> getLhs() {
//noinspection unchecked //noinspection unchecked

View File

@ -237,6 +237,36 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
return path; return path;
} }
@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(Class<S> treatJavaType) {
return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) );
}
@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(EntityDomainType<S> treatTarget) {
return getTreatedPath( treatTarget );
}
@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(Class<S> treatJavaType, String alias) {
return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) );
}
@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(EntityDomainType<S> treatTarget, String alias) {
return getTreatedPath( treatTarget );
}
@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(Class<S> treatJavaType, String alias, boolean fetch) {
return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) );
}
@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch) {
return null;
}
/** /**
* Utility that checks if this path's parent navigable path is compatible with the specified SQM parent, * 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. * and if not creates a copy of the navigable path with the correct parent.

View File

@ -58,9 +58,33 @@ public class NonAggregatedCompositeSimplePath<T> extends SqmEntityValuedSimplePa
return walker.visitNonAggregatedCompositeValuedPath( this ); return walker.visitNonAggregatedCompositeValuedPath( this );
} }
@Override
public <S extends T> SqmTreatedSimplePath<T, S> treatAs(Class<S> treatJavaType) throws PathException {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
}
@Override @Override
public <S extends T> SqmTreatedPath<T, S> treatAs(EntityDomainType<S> treatTarget) throws PathException { public <S extends T> SqmTreatedSimplePath<T, S> treatAs(EntityDomainType<S> treatTarget) throws PathException {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
}
@Override
public <S extends T> SqmTreatedSimplePath<T, S> treatAs(Class<S> treatJavaType, String alias) {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
}
@Override
public <S extends T> SqmTreatedSimplePath<T, S> treatAs(EntityDomainType<S> treatTarget, String alias) {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
}
@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(Class<S> treatJavaType, String alias, boolean fetch) {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
}
@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch) {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" ); throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
} }

View File

@ -117,12 +117,12 @@ public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> {
} }
@Override @Override
public <S extends T> SqmTreatedFrom<T, T, S> treatAs(Class<S> treatJavaType, String alias) { public <S extends T> SqmTreatedRoot treatAs(Class<S> treatJavaType, String alias) {
throw new UnsupportedOperationException( "Derived roots can not be treated" ); throw new UnsupportedOperationException( "Derived roots can not be treated" );
} }
@Override @Override
public <S extends T> SqmTreatedFrom<T, T, S> treatAs(EntityDomainType<S> treatTarget, String alias) { public <S extends T> SqmTreatedRoot treatAs(EntityDomainType<S> treatTarget, String alias) {
throw new UnsupportedOperationException( "Derived roots can not be treated" ); throw new UnsupportedOperationException( "Derived roots can not be treated" );
} }
} }

View File

@ -185,6 +185,20 @@ public class SqmMapJoin<L, K, V>
return treat; return treat;
} }
@Override
public <S extends V> SqmTreatedMapJoin<L, K, V, S> treatAs(Class<S> treatJavaType, String alias, boolean fetched) {
return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias, fetched );
}
@Override
public <S extends V> SqmTreatedMapJoin<L, K, V, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetched) {
final SqmTreatedMapJoin<L, K, V, S> treat = findTreat( treatTarget, alias );
if ( treat == null ) {
return addTreat( new SqmTreatedMapJoin<>( this, treatTarget, alias ) );
}
return treat;
}
@Override @Override
public SqmMapJoin<L, K, V> makeCopy(SqmCreationProcessingState creationProcessingState) { public SqmMapJoin<L, K, V> makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmMapJoin<>( return new SqmMapJoin<>(

View File

@ -125,6 +125,14 @@ public interface SqmPath<T> extends SqmExpression<T>, SemanticPathPart, JpaPath<
@Override @Override
<S extends T> SqmTreatedPath<T,S> treatAs(EntityDomainType<S> treatTarget); <S extends T> SqmTreatedPath<T,S> treatAs(EntityDomainType<S> treatTarget);
<S extends T> SqmTreatedPath<T,S> treatAs(Class<S> treatJavaType, String alias);
<S extends T> SqmTreatedPath<T,S> treatAs(EntityDomainType<S> treatTarget, String alias);
<S extends T> SqmTreatedPath<T,S> treatAs(Class<S> treatJavaType, String alias, boolean fetch);
<S extends T> SqmTreatedPath<T,S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch);
default SqmRoot<?> findRoot() { default SqmRoot<?> findRoot() {
final SqmPath<?> lhs = getLhs(); final SqmPath<?> lhs = getLhs();
if ( lhs != null ) { if ( lhs != null ) {

View File

@ -10,7 +10,6 @@ import java.util.Locale;
import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.spi.NavigablePath;
import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmPathSource; 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.SqmJoinType;
import org.hibernate.query.sqm.tree.from.SqmFrom; import org.hibernate.query.sqm.tree.from.SqmFrom;
import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.spi.NavigablePath;
/** /**
* @author Christian Beikov * @author Christian Beikov
@ -99,30 +99,50 @@ public class SqmPluralPartJoin<O,T> extends AbstractSqmJoin<O,T> {
public <X> X accept(SemanticQueryWalker<X> walker) { public <X> X accept(SemanticQueryWalker<X> walker) {
return walker.visitPluralPartJoin( this ); return walker.visitPluralPartJoin( this );
} }
//
// @Override @SuppressWarnings("unchecked")
// public <S extends T> SqmTreatedPluralPartJoin<O,T,S> treatAs(Class<S> treatJavaType) { @Override
// return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) ); public <S extends T> SqmTreatedPluralPartJoin treatAs(Class<S> treatJavaType) {
// } return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) );
// }
// @Override
// public <S extends T> SqmTreatedPluralPartJoin<O,T,S> treatAs(EntityDomainType<S> treatTarget) { @SuppressWarnings("unchecked")
// return treatAs( treatTarget, null ); @Override
// } public <S extends T> SqmTreatedPluralPartJoin treatAs(EntityDomainType<S> treatTarget) {
// return treatAs( treatTarget, null );
// @Override }
// public <S extends T> SqmTreatedPluralPartJoin<O,T,S> treatAs(Class<S> treatJavaType, String alias) {
// return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias ); @SuppressWarnings("unchecked")
// } @Override
// public <S extends T> SqmTreatedPluralPartJoin treatAs(Class<S> treatJavaType, String alias) {
// @Override return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias );
// public <S extends T> SqmTreatedPluralPartJoin<O,T,S> treatAs(EntityDomainType<S> treatTarget, String alias) { }
// final SqmTreatedPluralPartJoin<O, T, S> treat = findTreat( treatTarget, alias );
// if ( treat == null ) { @SuppressWarnings("unchecked")
// return addTreat( new SqmTreatedPluralPartJoin<>( this, treatTarget, alias ) ); @Override
// } public <S extends T> SqmTreatedPluralPartJoin treatAs(EntityDomainType<S> treatTarget, String alias) {
// return treat; final SqmTreatedPluralPartJoin treat = findTreat( treatTarget, alias );
// } if ( treat == null ) {
return addTreat( new SqmTreatedPluralPartJoin( this, treatTarget, alias ) );
}
return treat;
}
@SuppressWarnings("unchecked")
@Override
public <S extends T> SqmTreatedPluralPartJoin treatAs(Class<S> treatJavaType, String alias, boolean fetch) {
return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias, fetch );
}
@SuppressWarnings("unchecked")
@Override
public <S extends T> SqmTreatedPluralPartJoin treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch) {
final SqmTreatedPluralPartJoin treat = findTreat( treatTarget, alias );
if ( treat == null ) {
return addTreat( new SqmTreatedPluralPartJoin( this, treatTarget, alias ) );
}
return treat;
}
@Override @Override
@ -130,26 +150,6 @@ public class SqmPluralPartJoin<O,T> extends AbstractSqmJoin<O,T> {
return null; return null;
} }
@Override
public <S extends T> SqmTreatedPluralPartJoin<O, T, S> treatAs(Class<S> treatJavaType) {
return null;
}
@Override
public <S extends T> SqmTreatedJoin<O, T, S> treatAs(EntityDomainType<S> treatTarget) {
return null;
}
@Override
public <S extends T> SqmTreatedJoin<O, T, S> treatAs(Class<S> treatJavaType, String alias) {
return null;
}
@Override
public <S extends T> SqmTreatedJoin<O, T, S> treatAs(EntityDomainType<S> treatTarget, String alias) {
return null;
}
@Override @Override
public SqmCorrelatedPluralPartJoin<O, T> createCorrelation() { public SqmCorrelatedPluralPartJoin<O, T> createCorrelation() {
return new SqmCorrelatedPluralPartJoin<>( this ); return new SqmCorrelatedPluralPartJoin<>( this );

View File

@ -27,6 +27,12 @@ public interface SqmTreatedFrom<L,R,R1 extends R> extends SqmFrom<L,R1>, SqmTrea
@Override @Override
<S extends R1> SqmTreatedFrom<L, R1, S> treatAs(EntityDomainType<S> treatTarget, String alias); <S extends R1> SqmTreatedFrom<L, R1, S> treatAs(EntityDomainType<S> treatTarget, String alias);
@Override
<S extends R1> SqmTreatedFrom<L, R1, S> treatAs(Class<S> treatJavaType, String alias, boolean fetch);
@Override
<S extends R1> SqmTreatedFrom<L, R1, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch);
@Override @Override
SqmTreatedFrom<L,R,R1> copy(SqmCopyContext context); SqmTreatedFrom<L,R,R1> copy(SqmCopyContext context);
} }

View File

@ -27,6 +27,7 @@ public class SqmTreatedMapJoin<L, K, V, S extends V> extends SqmMapJoin<L, K, S>
private final SqmMapJoin<L, K, V> wrappedPath; private final SqmMapJoin<L, K, V> wrappedPath;
private final TreatableDomainType<S> treatTarget; private final TreatableDomainType<S> treatTarget;
@SuppressWarnings({ "rawtypes" })
public SqmTreatedMapJoin( public SqmTreatedMapJoin(
SqmMapJoin<L, K, V> wrappedPath, SqmMapJoin<L, K, V> wrappedPath,
TreatableDomainType<S> treatTarget, TreatableDomainType<S> treatTarget,
@ -34,12 +35,12 @@ public class SqmTreatedMapJoin<L, K, V, S extends V> extends SqmMapJoin<L, K, S>
this( wrappedPath, treatTarget, alias, false ); this( wrappedPath, treatTarget, alias, false );
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
public SqmTreatedMapJoin( public SqmTreatedMapJoin(
SqmMapJoin<L, K, V> wrappedPath, SqmMapJoin<L, K, V> wrappedPath,
TreatableDomainType<S> treatTarget, TreatableDomainType<S> treatTarget,
String alias, String alias,
boolean fetched) { boolean fetched) {
//noinspection unchecked
super( super(
wrappedPath.getLhs(), wrappedPath.getLhs(),
wrappedPath.getNavigablePath() wrappedPath.getNavigablePath()

View File

@ -27,4 +27,5 @@ public interface SqmTreatedPath<T, S extends T> extends JpaTreatedPath<T,S>, Sqm
@Override @Override
<S1 extends S> SqmTreatedPath<S, S1> treatAs(EntityDomainType<S1> treatTarget); <S1 extends S> SqmTreatedPath<S, S1> treatAs(EntityDomainType<S1> treatTarget);
} }

View File

@ -9,28 +9,28 @@ package org.hibernate.query.sqm.tree.domain;
import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmFrom;
import org.hibernate.spi.NavigablePath; import org.hibernate.spi.NavigablePath;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoin<O,S> implements SqmTreatedJoin<O,T,S> { @SuppressWarnings("rawtypes")
private final SqmPluralPartJoin<O,T> wrappedPath; public class SqmTreatedPluralPartJoin extends SqmPluralPartJoin implements SqmTreatedJoin {
private final EntityDomainType<S> treatTarget; private final SqmPluralPartJoin wrappedPath;
private final EntityDomainType treatTarget;
public SqmTreatedPluralPartJoin( public SqmTreatedPluralPartJoin(
SqmPluralPartJoin<O,T> wrappedPath, SqmPluralPartJoin wrappedPath,
EntityDomainType<S> treatTarget, EntityDomainType treatTarget,
String alias) { String alias) {
//noinspection unchecked //noinspection unchecked
super( super(
(SqmFrom<?, O>) wrappedPath.getLhs(), wrappedPath.getLhs(),
wrappedPath.getNavigablePath().treatAs( wrappedPath.getNavigablePath().treatAs(
treatTarget.getHibernateEntityName(), treatTarget.getHibernateEntityName(),
alias alias
), ),
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(), wrappedPath.getReferencedPathSource(),
alias, alias,
wrappedPath.getSqmJoinType(), wrappedPath.getSqmJoinType(),
wrappedPath.nodeBuilder() wrappedPath.nodeBuilder()
@ -41,14 +41,14 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
private SqmTreatedPluralPartJoin( private SqmTreatedPluralPartJoin(
NavigablePath navigablePath, NavigablePath navigablePath,
SqmPluralPartJoin<O,T> wrappedPath, SqmPluralPartJoin wrappedPath,
EntityDomainType<S> treatTarget, EntityDomainType treatTarget,
String alias) { String alias) {
//noinspection unchecked //noinspection unchecked
super( super(
(SqmFrom<?, O>) wrappedPath.getLhs(), wrappedPath.getLhs(),
navigablePath, navigablePath,
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(), wrappedPath.getReferencedPathSource(),
alias, alias,
wrappedPath.getSqmJoinType(), wrappedPath.getSqmJoinType(),
wrappedPath.nodeBuilder() wrappedPath.nodeBuilder()
@ -58,14 +58,14 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
} }
@Override @Override
public SqmTreatedPluralPartJoin<O, T, S> copy(SqmCopyContext context) { public SqmTreatedPluralPartJoin copy(SqmCopyContext context) {
final SqmTreatedPluralPartJoin<O, T, S> existing = context.getCopy( this ); final SqmTreatedPluralPartJoin existing = context.getCopy( this );
if ( existing != null ) { if ( existing != null ) {
return existing; return existing;
} }
final SqmTreatedPluralPartJoin<O, T, S> path = context.registerCopy( final SqmTreatedPluralPartJoin path = context.registerCopy(
this, this,
new SqmTreatedPluralPartJoin<>( new SqmTreatedPluralPartJoin(
getNavigablePath(), getNavigablePath(),
wrappedPath.copy( context ), wrappedPath.copy( context ),
treatTarget, treatTarget,
@ -77,22 +77,22 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
} }
@Override @Override
public SqmPluralPartJoin<O,T> getWrappedPath() { public SqmPluralPartJoin getWrappedPath() {
return wrappedPath; return wrappedPath;
} }
@Override @Override
public EntityDomainType<S> getTreatTarget() { public EntityDomainType getTreatTarget() {
return treatTarget; return treatTarget;
} }
@Override @Override
public SqmPathSource<S> getNodeType() { public SqmPathSource getNodeType() {
return treatTarget; return treatTarget;
} }
@Override @Override
public SqmPathSource<S> getReferencedPathSource() { public SqmPathSource getReferencedPathSource() {
return treatTarget; return treatTarget;
} }
@ -102,23 +102,39 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
} }
@Override @Override
public <S1 extends S> SqmTreatedPluralPartJoin<O, S, S1> treatAs(Class<S1> treatJavaType) { public SqmTreatedPluralPartJoin treatAs(Class treatJavaType) {
//noinspection unchecked
return super.treatAs( treatJavaType ); return super.treatAs( treatJavaType );
} }
@Override @Override
public <S1 extends S> SqmTreatedPluralPartJoin<O, S, S1> treatAs(EntityDomainType<S1> treatTarget) { public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget) {
return (SqmTreatedPluralPartJoin<O, S, S1>) super.treatAs( treatTarget ); //noinspection unchecked
return (SqmTreatedPluralPartJoin) super.treatAs( treatTarget );
} }
@Override @Override
public <S1 extends S> SqmTreatedPluralPartJoin<O, S, S1> treatAs(Class<S1> treatJavaType, String alias) { public SqmTreatedPluralPartJoin treatAs(Class treatJavaType, String alias) {
return (SqmTreatedPluralPartJoin<O, S, S1>) super.treatAs( treatJavaType, alias ); //noinspection unchecked
return (SqmTreatedPluralPartJoin) super.treatAs( treatJavaType, alias );
} }
@Override @Override
public <S1 extends S> SqmTreatedPluralPartJoin<O, S, S1> treatAs(EntityDomainType<S1> treatTarget, String alias) { public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget, String alias) {
return (SqmTreatedPluralPartJoin<O, S, S1>) super.treatAs( treatTarget, 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 );
} }

View File

@ -17,14 +17,15 @@ import org.hibernate.spi.NavigablePath;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTreatedFrom<S,T,S> { @SuppressWarnings("rawtypes")
private final SqmRoot<T> wrappedPath; public class SqmTreatedRoot extends SqmRoot implements SqmTreatedFrom {
private final EntityDomainType<S> treatTarget; private final SqmRoot wrappedPath;
private final EntityDomainType treatTarget;
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
public SqmTreatedRoot( public SqmTreatedRoot(
SqmRoot<T> wrappedPath, SqmRoot wrappedPath,
EntityDomainType<S> treatTarget) { EntityDomainType treatTarget) {
super( super(
wrappedPath.getNavigablePath().treatAs( wrappedPath.getNavigablePath().treatAs(
treatTarget.getHibernateEntityName() treatTarget.getHibernateEntityName()
@ -40,8 +41,8 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
private SqmTreatedRoot( private SqmTreatedRoot(
NavigablePath navigablePath, NavigablePath navigablePath,
SqmRoot<T> wrappedPath, SqmRoot wrappedPath,
EntityDomainType<S> treatTarget) { EntityDomainType treatTarget) {
super( super(
navigablePath, navigablePath,
(EntityDomainType) wrappedPath.getReferencedPathSource(), (EntityDomainType) wrappedPath.getReferencedPathSource(),
@ -53,14 +54,14 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
} }
@Override @Override
public SqmTreatedRoot<T,S> copy(SqmCopyContext context) { public SqmTreatedRoot copy(SqmCopyContext context) {
final SqmTreatedRoot<T, S> existing = context.getCopy( this ); final SqmTreatedRoot existing = context.getCopy( this );
if ( existing != null ) { if ( existing != null ) {
return existing; return existing;
} }
final SqmTreatedRoot<T, S> path = context.registerCopy( final SqmTreatedRoot path = context.registerCopy(
this, this,
new SqmTreatedRoot<>( new SqmTreatedRoot(
getNavigablePath(), getNavigablePath(),
wrappedPath.copy( context ), wrappedPath.copy( context ),
treatTarget treatTarget
@ -71,27 +72,27 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
} }
@Override @Override
public EntityDomainType<S> getTreatTarget() { public EntityDomainType getTreatTarget() {
return treatTarget; return treatTarget;
} }
@Override @Override
public EntityDomainType<S> getManagedType() { public EntityDomainType getManagedType() {
return getTreatTarget(); return getTreatTarget();
} }
@Override @Override
public SqmPath<T> getWrappedPath() { public SqmPath getWrappedPath() {
return wrappedPath; return wrappedPath;
} }
@Override @Override
public SqmPathSource<S> getNodeType() { public SqmPathSource getNodeType() {
return treatTarget; return treatTarget;
} }
@Override @Override
public EntityDomainType<S> getReferencedPathSource() { public EntityDomainType getReferencedPathSource() {
return getTreatTarget(); return getTreatTarget();
} }
@ -100,8 +101,9 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
return wrappedPath.getLhs(); return wrappedPath.getLhs();
} }
@SuppressWarnings("unchecked")
@Override @Override
public <X> X accept(SemanticQueryWalker<X> walker) { public Object accept(SemanticQueryWalker walker) {
return walker.visitTreatedPath( this ); return walker.visitTreatedPath( this );
} }

View File

@ -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.AbstractSqmFrom;
import org.hibernate.query.sqm.tree.domain.SqmCorrelatedCrossJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedCrossJoin;
import org.hibernate.query.sqm.tree.domain.SqmTreatedCrossJoin; 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.SqmPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmPredicateCollection; import org.hibernate.query.sqm.tree.predicate.SqmPredicateCollection;
import org.hibernate.query.sqm.tree.predicate.SqmWhereClause; import org.hibernate.query.sqm.tree.predicate.SqmWhereClause;
@ -189,6 +190,17 @@ public class SqmCrossJoin<T> extends AbstractSqmFrom<T, T> implements JpaCrossJo
public <S extends T> SqmTreatedCrossJoin treatAs(EntityDomainType<S> treatTarget, String alias) { public <S extends T> SqmTreatedCrossJoin treatAs(EntityDomainType<S> treatTarget, String alias) {
throw new UnsupportedOperationException( "Cross join treats can not be aliased" ); throw new UnsupportedOperationException( "Cross join treats can not be aliased" );
} }
@Override
public <S extends T> SqmTreatedFrom<T, T, S> treatAs(Class<S> treatJavaType, String alias, boolean fetch) {
return null;
}
@Override
public <S extends T> SqmTreatedFrom<T, T, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch) {
return null;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <S extends T> SqmTreatedCrossJoin treatAs(Class<S> treatAsType) { public <S extends T> SqmTreatedCrossJoin treatAs(Class<S> treatAsType) {

View File

@ -137,6 +137,16 @@ public class SqmCteJoin<T> extends AbstractSqmJoin<T, T> {
throw new UnsupportedOperationException( "CTE joins can not be treated" ); throw new UnsupportedOperationException( "CTE joins can not be treated" );
} }
@Override
public <S extends T> SqmTreatedJoin<T, T, S> treatAs(Class<S> treatJavaType, String alias, boolean fetched) {
throw new UnsupportedOperationException( "CTE joins can not be treated" );
}
@Override
public <S extends T> SqmTreatedJoin<T, T, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetched) {
throw new UnsupportedOperationException( "CTE joins can not be treated" );
}
@Override @Override
public SqmFrom<?, T> getParent() { public SqmFrom<?, T> getParent() {
return getCorrelationParent(); return getCorrelationParent();

View File

@ -192,6 +192,16 @@ public class SqmDerivedJoin<T> extends AbstractSqmJoin<T, T> implements JpaDeriv
throw new UnsupportedOperationException( "Derived joins can not be treated" ); throw new UnsupportedOperationException( "Derived joins can not be treated" );
} }
@Override
public <S extends T> SqmTreatedJoin<T, T, S> treatAs(Class<S> treatJavaType, String alias, boolean fetched) {
throw new UnsupportedOperationException( "Derived joins can not be treated" );
}
@Override
public <S extends T> SqmTreatedJoin<T, T, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetched) {
throw new UnsupportedOperationException( "Derived joins can not be treated" );
}
@Override @Override
public PersistentAttribute<? super T, ?> getAttribute() { public PersistentAttribute<? super T, ?> getAttribute() {
// none // none

View File

@ -194,6 +194,16 @@ public class SqmEntityJoin<L,R> extends AbstractSqmJoin<L,R> implements SqmSingu
throw new UnsupportedOperationException( "Entity join treats can not be aliased" ); throw new UnsupportedOperationException( "Entity join treats can not be aliased" );
} }
@Override
public <S extends R> SqmTreatedEntityJoin<L,R,S> treatAs(Class<S> treatJavaType, String alias, boolean fetched) {
throw new UnsupportedOperationException( "Entity join treats can not be aliased" );
}
@Override
public <S extends R> SqmTreatedEntityJoin<L,R,S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetched) {
throw new UnsupportedOperationException( "Entity join treats can not be aliased" );
}
@Override @Override
public PersistentAttribute<? super L, ?> getAttribute() { public PersistentAttribute<? super L, ?> getAttribute() {
// there is no attribute // there is no attribute

View File

@ -17,7 +17,6 @@ import jakarta.persistence.metamodel.SetAttribute;
import jakarta.persistence.metamodel.SingularAttribute; import jakarta.persistence.metamodel.SingularAttribute;
import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.criteria.JpaEntityJoin;
import org.hibernate.query.criteria.JpaFrom; import org.hibernate.query.criteria.JpaFrom;
import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmCopyContext;
@ -82,8 +81,10 @@ public interface SqmFrom<L, R> extends SqmVisitableNode, SqmPath<R>, JpaFrom<L,
@Override @Override
<S extends R> SqmTreatedFrom<L,R,S> treatAs(EntityDomainType<S> treatTarget); <S extends R> SqmTreatedFrom<L,R,S> treatAs(EntityDomainType<S> treatTarget);
@Override
<S extends R> SqmTreatedFrom<L,R,S> treatAs(Class<S> treatJavaType, String alias); <S extends R> SqmTreatedFrom<L,R,S> treatAs(Class<S> treatJavaType, String alias);
@Override
<S extends R> SqmTreatedFrom<L,R,S> treatAs(EntityDomainType<S> treatTarget, String alias); <S extends R> SqmTreatedFrom<L,R,S> treatAs(EntityDomainType<S> treatTarget, String alias);

View File

@ -11,7 +11,9 @@ import java.util.List;
import org.hibernate.Internal; import org.hibernate.Internal;
import org.hibernate.metamodel.model.domain.EntityDomainType; 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.SqmTreatedFrom;
import org.hibernate.query.sqm.tree.domain.SqmTreatedPath;
import org.hibernate.spi.NavigablePath; import org.hibernate.spi.NavigablePath;
import org.hibernate.query.PathException; import org.hibernate.query.PathException;
import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.criteria.JpaRoot;
@ -206,14 +208,28 @@ public class SqmRoot<E> extends AbstractSqmFrom<E,E> implements JpaRoot<E> {
return treat; return treat;
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override @Override
public <S extends E> SqmTreatedFrom<E,E,S> treatAs(Class<S> treatJavaType, String alias) { public <S extends E> SqmTreatedRoot treatAs(Class<S> treatJavaType, String alias) {
throw new UnsupportedOperationException( "Root treats can not be aliased" ); throw new UnsupportedOperationException( "Root treats can not be aliased" );
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override @Override
public <S extends E> SqmTreatedFrom<E,E,S> treatAs(EntityDomainType<S> treatTarget, String alias) { public <S extends E> SqmTreatedRoot treatAs(EntityDomainType<S> treatTarget, String alias) {
throw new UnsupportedOperationException( "Root treats can not be aliased" ); throw new UnsupportedOperationException( "Root treats can not be aliased" );
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <S extends E> SqmTreatedRoot treatAs(Class<S> treatJavaType, String alias, boolean fetch) {
throw new TreatException( "Root paths cannot be aliased, nor fetched - " + getNavigablePath().getFullPath() );
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <S extends E> SqmTreatedRoot treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch) {
throw new TreatException( "Root paths cannot be aliased, nor fetched - " + getNavigablePath().getFullPath() );
}
} }

View File

@ -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.cte.SqmCteStatement;
import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter; import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter;
import org.hibernate.query.sqm.tree.expression.SqmParameter; 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.from.SqmFromClause;
import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.query.sqm.tree.from.SqmRoot; import org.hibernate.query.sqm.tree.from.SqmRoot;
@ -517,6 +519,8 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
query.select( nodeBuilder().count() ); query.select( nodeBuilder().count() );
return query; return query;
} }
querySpec.getSelectClause().setSelection( (SqmSelectableNode<?>) nodeBuilder.tuple( subSelections ) );
} }
private <S> void aliasSelections(SqmQueryPart<S> queryPart) { private <S> void aliasSelections(SqmQueryPart<S> queryPart) {