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;
}
for ( AccessType accessType : AccessType.values() ) {
if ( accessType.getExternalName().equalsIgnoreCase( externalName ) ) {
if ( accessType.getExternalName().equals( externalName ) ) {
return accessType;
}
}

View File

@ -30,13 +30,39 @@ public interface DiscriminatorSqmPath<T> extends SqmPath<T> {
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" );
}
}

View File

@ -47,5 +47,4 @@ public class AnyDiscriminatorSqmPath<T> extends AbstractSqmPath<T> implements Di
public AnyDiscriminatorSqmPathSource<T> getExpressible() {
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.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 <X, T extends X> SqmRoot<T> treat(Root<X> root, Class<T> type) {
//noinspection unchecked
return (SqmTreatedRoot<X,T>) ( (SqmRoot<X>) root ).treatAs( type );
return (SqmTreatedRoot) ( (SqmRoot<X>) root ).treatAs( type );
}
@Override

View File

@ -36,6 +36,7 @@ public abstract class AbstractSqmAttributeJoin<L, R>
private boolean fetched;
@SuppressWarnings({ "rawtypes", "unchecked" })
public AbstractSqmAttributeJoin(
SqmFrom<?, L> lhs,
SqmJoinable joinedNavigable,
@ -43,6 +44,7 @@ public abstract class AbstractSqmAttributeJoin<L, R>
SqmJoinType joinType,
boolean fetched,
NodeBuilder nodeBuilder) {
//noinspection StringEquality
this(
lhs,
joinedNavigable.createNavigablePath( lhs, alias ),
@ -54,6 +56,7 @@ public abstract class AbstractSqmAttributeJoin<L, R>
);
}
@SuppressWarnings("rawtypes")
protected AbstractSqmAttributeJoin(
SqmFrom<?, L> lhs,
NavigablePath navigablePath,
@ -158,5 +161,11 @@ public abstract class AbstractSqmAttributeJoin<L, R>
@Override
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
public void appendHqlString(StringBuilder sb) {
if ( alias == null ) {

View File

@ -94,6 +94,12 @@ public abstract class AbstractSqmJoin<L, R> extends AbstractSqmFrom<L, R> implem
@Override
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
public SqmFrom<?, L> getLhs() {
//noinspection unchecked

View File

@ -237,6 +237,36 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
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,
* 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 );
}
@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
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" );
}

View File

@ -117,12 +117,12 @@ public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> {
}
@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" );
}
@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" );
}
}

View File

@ -185,6 +185,20 @@ public class SqmMapJoin<L, K, V>
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
public SqmMapJoin<L, K, V> makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmMapJoin<>(

View File

@ -125,6 +125,14 @@ public interface SqmPath<T> extends SqmExpression<T>, SemanticPathPart, JpaPath<
@Override
<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() {
final SqmPath<?> lhs = getLhs();
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.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<O,T> extends AbstractSqmJoin<O,T> {
public <X> X accept(SemanticQueryWalker<X> walker) {
return walker.visitPluralPartJoin( this );
}
//
// @Override
// public <S extends T> SqmTreatedPluralPartJoin<O,T,S> treatAs(Class<S> treatJavaType) {
// return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) );
// }
//
// @Override
// public <S extends T> SqmTreatedPluralPartJoin<O,T,S> 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 );
// }
//
// @Override
// 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 ) {
// return addTreat( new SqmTreatedPluralPartJoin<>( this, treatTarget, alias ) );
// }
// return treat;
// }
@SuppressWarnings("unchecked")
@Override
public <S extends T> SqmTreatedPluralPartJoin treatAs(Class<S> treatJavaType) {
return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ) );
}
@SuppressWarnings("unchecked")
@Override
public <S extends T> SqmTreatedPluralPartJoin treatAs(EntityDomainType<S> treatTarget) {
return treatAs( treatTarget, null );
}
@SuppressWarnings("unchecked")
@Override
public <S extends T> SqmTreatedPluralPartJoin treatAs(Class<S> treatJavaType, String alias) {
return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias );
}
@SuppressWarnings("unchecked")
@Override
public <S extends T> SqmTreatedPluralPartJoin treatAs(EntityDomainType<S> 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 <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
@ -130,26 +150,6 @@ public class SqmPluralPartJoin<O,T> extends AbstractSqmJoin<O,T> {
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
public SqmCorrelatedPluralPartJoin<O, T> createCorrelation() {
return new SqmCorrelatedPluralPartJoin<>( this );

View File

@ -27,6 +27,12 @@ public interface SqmTreatedFrom<L,R,R1 extends R> extends SqmFrom<L,R1>, SqmTrea
@Override
<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
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 TreatableDomainType<S> treatTarget;
@SuppressWarnings({ "rawtypes" })
public SqmTreatedMapJoin(
SqmMapJoin<L, K, V> wrappedPath,
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 );
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public SqmTreatedMapJoin(
SqmMapJoin<L, K, V> wrappedPath,
TreatableDomainType<S> treatTarget,
String alias,
boolean fetched) {
//noinspection unchecked
super(
wrappedPath.getLhs(),
wrappedPath.getNavigablePath()

View File

@ -27,4 +27,5 @@ public interface SqmTreatedPath<T, S extends T> extends JpaTreatedPath<T,S>, Sqm
@Override
<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.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<O,T, S extends T> extends SqmPluralPartJoin<O,S> implements SqmTreatedJoin<O,T,S> {
private final SqmPluralPartJoin<O,T> wrappedPath;
private final EntityDomainType<S> treatTarget;
@SuppressWarnings("rawtypes")
public class SqmTreatedPluralPartJoin extends SqmPluralPartJoin implements SqmTreatedJoin {
private final SqmPluralPartJoin wrappedPath;
private final EntityDomainType treatTarget;
public SqmTreatedPluralPartJoin(
SqmPluralPartJoin<O,T> wrappedPath,
EntityDomainType<S> treatTarget,
SqmPluralPartJoin wrappedPath,
EntityDomainType treatTarget,
String alias) {
//noinspection unchecked
super(
(SqmFrom<?, O>) wrappedPath.getLhs(),
wrappedPath.getLhs(),
wrappedPath.getNavigablePath().treatAs(
treatTarget.getHibernateEntityName(),
alias
),
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(),
wrappedPath.getReferencedPathSource(),
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.nodeBuilder()
@ -41,14 +41,14 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
private SqmTreatedPluralPartJoin(
NavigablePath navigablePath,
SqmPluralPartJoin<O,T> wrappedPath,
EntityDomainType<S> treatTarget,
SqmPluralPartJoin wrappedPath,
EntityDomainType treatTarget,
String alias) {
//noinspection unchecked
super(
(SqmFrom<?, O>) wrappedPath.getLhs(),
wrappedPath.getLhs(),
navigablePath,
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(),
wrappedPath.getReferencedPathSource(),
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.nodeBuilder()
@ -58,14 +58,14 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
}
@Override
public SqmTreatedPluralPartJoin<O, T, S> copy(SqmCopyContext context) {
final SqmTreatedPluralPartJoin<O, T, S> existing = context.getCopy( this );
public SqmTreatedPluralPartJoin copy(SqmCopyContext context) {
final SqmTreatedPluralPartJoin existing = context.getCopy( this );
if ( existing != null ) {
return existing;
}
final SqmTreatedPluralPartJoin<O, T, S> 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<O,T, S extends T> extends SqmPluralPartJoi
}
@Override
public SqmPluralPartJoin<O,T> getWrappedPath() {
public SqmPluralPartJoin getWrappedPath() {
return wrappedPath;
}
@Override
public EntityDomainType<S> getTreatTarget() {
public EntityDomainType getTreatTarget() {
return treatTarget;
}
@Override
public SqmPathSource<S> getNodeType() {
public SqmPathSource getNodeType() {
return treatTarget;
}
@Override
public SqmPathSource<S> getReferencedPathSource() {
public SqmPathSource getReferencedPathSource() {
return treatTarget;
}
@ -102,23 +102,39 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
}
@Override
public <S1 extends S> SqmTreatedPluralPartJoin<O, S, S1> treatAs(Class<S1> treatJavaType) {
public SqmTreatedPluralPartJoin treatAs(Class treatJavaType) {
//noinspection unchecked
return super.treatAs( treatJavaType );
}
@Override
public <S1 extends S> SqmTreatedPluralPartJoin<O, S, S1> treatAs(EntityDomainType<S1> treatTarget) {
return (SqmTreatedPluralPartJoin<O, S, S1>) super.treatAs( treatTarget );
public SqmTreatedPluralPartJoin treatAs(EntityDomainType treatTarget) {
//noinspection unchecked
return (SqmTreatedPluralPartJoin) super.treatAs( treatTarget );
}
@Override
public <S1 extends S> SqmTreatedPluralPartJoin<O, S, S1> treatAs(Class<S1> treatJavaType, String alias) {
return (SqmTreatedPluralPartJoin<O, S, S1>) super.treatAs( treatJavaType, alias );
public SqmTreatedPluralPartJoin treatAs(Class treatJavaType, String alias) {
//noinspection unchecked
return (SqmTreatedPluralPartJoin) super.treatAs( treatJavaType, alias );
}
@Override
public <S1 extends S> SqmTreatedPluralPartJoin<O, S, S1> treatAs(EntityDomainType<S1> treatTarget, String alias) {
return (SqmTreatedPluralPartJoin<O, S, S1>) 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 );
}

View File

@ -17,14 +17,15 @@ import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
*/
public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTreatedFrom<S,T,S> {
private final SqmRoot<T> wrappedPath;
private final EntityDomainType<S> treatTarget;
@SuppressWarnings("rawtypes")
public class SqmTreatedRoot extends SqmRoot implements SqmTreatedFrom {
private final SqmRoot wrappedPath;
private final EntityDomainType treatTarget;
@SuppressWarnings({ "unchecked", "rawtypes" })
public SqmTreatedRoot(
SqmRoot<T> wrappedPath,
EntityDomainType<S> treatTarget) {
SqmRoot wrappedPath,
EntityDomainType treatTarget) {
super(
wrappedPath.getNavigablePath().treatAs(
treatTarget.getHibernateEntityName()
@ -40,8 +41,8 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
@SuppressWarnings({ "unchecked", "rawtypes" })
private SqmTreatedRoot(
NavigablePath navigablePath,
SqmRoot<T> wrappedPath,
EntityDomainType<S> treatTarget) {
SqmRoot wrappedPath,
EntityDomainType treatTarget) {
super(
navigablePath,
(EntityDomainType) wrappedPath.getReferencedPathSource(),
@ -53,14 +54,14 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
}
@Override
public SqmTreatedRoot<T,S> copy(SqmCopyContext context) {
final SqmTreatedRoot<T, S> existing = context.getCopy( this );
public SqmTreatedRoot copy(SqmCopyContext context) {
final SqmTreatedRoot existing = context.getCopy( this );
if ( existing != null ) {
return existing;
}
final SqmTreatedRoot<T, S> 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<T, S extends T> extends SqmRoot<S> implements SqmTre
}
@Override
public EntityDomainType<S> getTreatTarget() {
public EntityDomainType getTreatTarget() {
return treatTarget;
}
@Override
public EntityDomainType<S> getManagedType() {
public EntityDomainType getManagedType() {
return getTreatTarget();
}
@Override
public SqmPath<T> getWrappedPath() {
public SqmPath getWrappedPath() {
return wrappedPath;
}
@Override
public SqmPathSource<S> getNodeType() {
public SqmPathSource getNodeType() {
return treatTarget;
}
@Override
public EntityDomainType<S> getReferencedPathSource() {
public EntityDomainType getReferencedPathSource() {
return getTreatTarget();
}
@ -100,8 +101,9 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
return wrappedPath.getLhs();
}
@SuppressWarnings("unchecked")
@Override
public <X> X accept(SemanticQueryWalker<X> walker) {
public Object accept(SemanticQueryWalker walker) {
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.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<T> extends AbstractSqmFrom<T, T> implements JpaCrossJo
public <S extends T> SqmTreatedCrossJoin treatAs(EntityDomainType<S> treatTarget, String alias) {
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")
@Override
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" );
}
@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
public SqmFrom<?, T> getParent() {
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" );
}
@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
public PersistentAttribute<? super T, ?> getAttribute() {
// 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" );
}
@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
public PersistentAttribute<? super L, ?> getAttribute() {
// there is no attribute

View File

@ -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<L, R> extends SqmVisitableNode, SqmPath<R>, JpaFrom<L,
@Override
<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);
@Override
<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.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<E> extends AbstractSqmFrom<E,E> implements JpaRoot<E> {
return treat;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@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" );
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@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" );
}
@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.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<T> extends AbstractSqmSelectQuery<T> implements
query.select( nodeBuilder().count() );
return query;
}
querySpec.getSelectClause().setSelection( (SqmSelectableNode<?>) nodeBuilder.tuple( subSelections ) );
}
private <S> void aliasSelections(SqmQueryPart<S> queryPart) {