Skip to content

Commit b788d42

Browse files
committed
HHH-19116 Return actual path source for singular attribute joins
This fixes the check for `fk()` function argument type
1 parent 88c9758 commit b788d42

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleType.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.List;
1212
import java.util.Map;
1313

14+
import jakarta.persistence.metamodel.Bindable;
1415
import org.hibernate.Incubating;
1516
import org.hibernate.internal.util.collections.CollectionHelper;
1617
import org.hibernate.metamodel.UnsupportedMappingException;
@@ -31,6 +32,7 @@
3132
import org.hibernate.query.sqm.tree.select.SqmSubQuery;
3233
import org.hibernate.sql.ast.spi.FromClauseAccess;
3334
import org.hibernate.sql.ast.spi.SqlSelection;
35+
import org.hibernate.type.BasicType;
3436
import org.hibernate.type.descriptor.java.JavaType;
3537
import org.hibernate.type.descriptor.java.ObjectArrayJavaType;
3638

@@ -177,20 +179,21 @@ public SqmPathSource<?> findSubPathSource(String name) {
177179
final SqmSelectableNode<?> component = components[index];
178180
if ( component instanceof SqmPath<?> ) {
179181
final SqmPath<?> sqmPath = (SqmPath<?>) component;
180-
if ( sqmPath.getNodeType() instanceof SingularPersistentAttribute<?, ?> ) {
182+
final Bindable<?> model = sqmPath.getModel();
183+
if ( model instanceof SingularPersistentAttribute<?, ?> ) {
181184
//noinspection unchecked,rawtypes
182185
return new AnonymousTupleSqmAssociationPathSource(
183186
name,
184187
sqmPath,
185-
( (SingularPersistentAttribute<?, ?>) sqmPath.getNodeType() ).getType()
188+
( (SingularPersistentAttribute<?, ?>) model ).getType()
186189
);
187190
}
188-
else if ( sqmPath.getNodeType() instanceof PluralPersistentAttribute<?, ?, ?> ) {
191+
else if ( model instanceof PluralPersistentAttribute<?, ?, ?> ) {
189192
//noinspection unchecked,rawtypes
190193
return new AnonymousTupleSqmAssociationPathSource(
191194
name,
192195
sqmPath,
193-
( (PluralPersistentAttribute<?, ?, ?>) sqmPath.getNodeType() ).getElementType()
196+
( (PluralPersistentAttribute<?, ?, ?>) model ).getElementType()
194197
);
195198
}
196199
else if ( sqmPath.getNodeType() instanceof EntityDomainType<?> ) {

hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private AttributeJoinDelegate resolveAlias(String identifier, boolean isTerminal
197197
if ( allowReuse ) {
198198
if ( !isTerminal ) {
199199
for ( SqmJoin<?, ?> sqmJoin : lhs.getSqmJoins() ) {
200-
if ( sqmJoin.getAlias() == null && sqmJoin.getReferencedPathSource() == subPathSource ) {
200+
if ( sqmJoin.getAlias() == null && sqmJoin.getModel() == subPathSource ) {
201201
return sqmJoin;
202202
}
203203
}

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public static <T, A> SqmAttributeJoin<T, A> findCompatibleFetchJoin(
427427
SqmPathSource<A> pathSource,
428428
SqmJoinType requestedJoinType) {
429429
for ( final SqmJoin<T, ?> join : sqmFrom.getSqmJoins() ) {
430-
if ( join.getReferencedPathSource() == pathSource ) {
430+
if ( join.getModel() == pathSource ) {
431431
final SqmAttributeJoin<T, ?> attributeJoin = (SqmAttributeJoin<T, ?>) join;
432432
if ( attributeJoin.isFetched() ) {
433433
final SqmJoinType joinType = join.getSqmJoinType();

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmAttributeJoin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public <X> X accept(SemanticQueryWalker<X> walker) {
122122
@Override
123123
public PersistentAttribute<? super O, ?> getAttribute() {
124124
//noinspection unchecked
125-
return (PersistentAttribute<? super O, ?>) getReferencedPathSource();
125+
return (PersistentAttribute<? super O, ?>) getModel();
126126
}
127127

128128
@Override

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
1515
import org.hibernate.metamodel.model.domain.TreatableDomainType;
1616
import org.hibernate.query.sqm.SemanticQueryWalker;
17+
import org.hibernate.query.sqm.SqmPathSource;
1718
import org.hibernate.spi.NavigablePath;
1819
import org.hibernate.query.hql.spi.SqmCreationProcessingState;
1920
import org.hibernate.query.sqm.NodeBuilder;
@@ -86,6 +87,16 @@ public SqmSingularJoin<O, T> copy(SqmCopyContext context) {
8687
return path;
8788
}
8889

90+
@Override
91+
public SqmPathSource<T> getNodeType() {
92+
return getReferencedPathSource();
93+
}
94+
95+
@Override
96+
public SqmPathSource<T> getReferencedPathSource() {
97+
return getModel().getPathSource();
98+
}
99+
89100
@Override
90101
public SingularPersistentAttribute<O, T> getModel() {
91102
return (SingularPersistentAttribute<O, T>) super.getNodeType();

0 commit comments

Comments
 (0)