Skip to content

Commit

Permalink
HHH-17386 Fix type inference source reset for top level predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Nov 6, 2023
1 parent 756f253 commit 30ab52d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6866,9 +6866,7 @@ public CaseSearchedExpression visitSearchedCaseExpression(SqmCaseSearched<?> exp

Expression otherwise = null;
for ( SqmCaseSearched.WhenFragment<?> whenFragment : expression.getWhenFragments() ) {
inferrableTypeAccessStack.push( () -> null );
final Predicate whenPredicate = visitNestedTopLevelPredicate( whenFragment.getPredicate() );
inferrableTypeAccessStack.pop();
final MappingModelExpressible<?> alreadyKnown = resolved;
inferrableTypeAccessStack.push(
() -> alreadyKnown == null && inferenceSupplier != null ? inferenceSupplier.get() : alreadyKnown
Expand Down Expand Up @@ -7056,7 +7054,9 @@ public Predicate visitNestedTopLevelPredicate(SqmPredicate predicate) {
originalConjunctTableGroupTreatUsages = new IdentityHashMap<>( tableGroupEntityNameUses );
}
tableGroupEntityNameUses.clear();
inferrableTypeAccessStack.push( this::getBooleanType );
final Predicate result = (Predicate) predicate.accept( this );
inferrableTypeAccessStack.pop();
final Predicate finalPredicate = combinePredicates(
result,
consumeConjunctTreatTypeRestrictions()
Expand Down Expand Up @@ -7866,7 +7866,9 @@ private JdbcMappingContainer getBooleanType() {

@Override
public Object visitBooleanExpressionPredicate(SqmBooleanExpressionPredicate predicate) {
inferrableTypeAccessStack.push( this::getBooleanType );
final Expression booleanExpression = (Expression) predicate.getBooleanExpression().accept( this );
inferrableTypeAccessStack.pop();
if ( booleanExpression instanceof SelfRenderingExpression ) {
final Predicate sqlPredicate = new SelfRenderingPredicate( (SelfRenderingExpression) booleanExpression );
if ( predicate.isNegated() ) {
Expand Down Expand Up @@ -7895,11 +7897,10 @@ public Object visitBooleanExpressionPredicate(SqmBooleanExpressionPredicate pred

@Override
public Object visitExistsPredicate(SqmExistsPredicate predicate) {
return new ExistsPredicate(
(SelectStatement) predicate.getExpression().accept( this ),
predicate.isNegated(),
getBooleanType()
);
inferrableTypeAccessStack.push( () -> null );
final SelectStatement selectStatement = (SelectStatement) predicate.getExpression().accept( this );
inferrableTypeAccessStack.pop();
return new ExistsPredicate( selectStatement, predicate.isNegated(), getBooleanType() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -61,6 +62,16 @@ public void testBinaryArithmeticInference() {

}

@Test
@JiraKey("HHH-17386")
public void testInferenceSourceResetForOnClause() {
doInHibernate( this::sessionFactory, session -> {
session.createQuery( "from Person p where p in (select p2 from Person p2 join Person p3 on exists (select 1 from Person p4))", Person.class )
.getResultList();
} );

}

@Entity(name = "Person")
public static class Person {

Expand Down

0 comments on commit 30ab52d

Please sign in to comment.