From e0875a127f07f8b04cc10646de3cd9160bc929af Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Thu, 23 Nov 2023 16:12:09 +0100 Subject: [PATCH] HHH-17445 Don't force initialization of correlated joined table group --- .../sqm/sql/BaseSqmToSqlAstConverter.java | 2 -- .../test/query/ImplicitJoinInSubqueryTest.java | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 2cbb5f024e..594b490616 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -3786,8 +3786,6 @@ public abstract class BaseSqmToSqlAstConverter extends Base querySpec::applyPredicate, this ); - // Force initialization of a possible lazy table group - tableGroup.getPrimaryTableReference(); querySpec.getFromClause().addRoot( tableGroup ); } else { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/ImplicitJoinInSubqueryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/ImplicitJoinInSubqueryTest.java index 78f59669d7..d4e448feac 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/ImplicitJoinInSubqueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/ImplicitJoinInSubqueryTest.java @@ -18,7 +18,6 @@ import org.assertj.core.api.Assertions; import static org.assertj.core.api.Assertions.assertThat; -@JiraKey("HHH-16721") @DomainModel(annotatedClasses = { ImplicitJoinInSubqueryTest.A.class, ImplicitJoinInSubqueryTest.B.class, @@ -28,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ImplicitJoinInSubqueryTest { @Test + @JiraKey("HHH-16721") public void testImplicitJoinInSubquery(SessionFactoryScope scope) { SQLStatementInspector statementInspector = scope.getCollectingStatementInspector(); statementInspector.clear(); @@ -41,6 +41,22 @@ public class ImplicitJoinInSubqueryTest { ); } + @Test + @JiraKey("HHH-17445") + public void testImplicitJoinInSubquery2(SessionFactoryScope scope) { + SQLStatementInspector statementInspector = scope.getCollectingStatementInspector(); + statementInspector.clear(); + scope.inTransaction( + entityManager -> { + entityManager.createSelectionQuery( + "select a from A a where exists (select 1 from B b where a.b.c is null)" + ).getResultList(); + assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "b1_0.c_id is null" ); + assertThat( statementInspector.getSqlQueries().get( 0 ) ).doesNotContain( ".id=b1_0.c_id" ); + } + ); + } + @Entity(name = "A") public static class A { @Id