Skip to content

Commit 27d66f8

Browse files
committed
HHH-19905 Force implicit joins to inner type on creation
1 parent 17eba45 commit 27d66f8

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public void consumeIdentifier(String identifier, boolean isBase, boolean isTermi
109109
assert delegate != null;
110110
delegate.consumeIdentifier(
111111
identifier,
112+
isTerminal,
112113
!nested && isTerminal,
113114
// Non-nested joins shall allow reuse, but nested ones (i.e. in treat)
114115
// only allow join reuse for non-terminal parts
@@ -254,7 +255,7 @@ else if ( fetch ) {
254255
}
255256

256257
private interface ConsumerDelegate {
257-
void consumeIdentifier(String identifier, boolean isTerminal, boolean allowReuse);
258+
void consumeIdentifier(String identifier, boolean originallyTerminal, boolean isTerminal, boolean allowReuse);
258259
void consumeTreat(String typeName, boolean isTerminal);
259260
SemanticPathPart getConsumedPart();
260261
}
@@ -282,11 +283,11 @@ private AttributeJoinDelegate(
282283
}
283284

284285
@Override
285-
public void consumeIdentifier(String identifier, boolean isTerminal, boolean allowReuse) {
286+
public void consumeIdentifier(String identifier, boolean originallyTerminal, boolean isTerminal, boolean allowReuse) {
286287
currentPath = createJoin(
287288
currentPath,
288289
identifier,
289-
joinType,
290+
originallyTerminal ? joinType : SqmJoinType.INNER,
290291
alias,
291292
fetch,
292293
isTerminal,
@@ -347,11 +348,11 @@ public ExpectingEntityJoinDelegate(
347348
this.fetch = fetch;
348349
this.alias = alias;
349350

350-
consumeIdentifier( identifier, isTerminal, true );
351+
consumeIdentifier( identifier, isTerminal, isTerminal, true );
351352
}
352353

353354
@Override
354-
public void consumeIdentifier(String identifier, boolean isTerminal, boolean allowReuse) {
355+
public void consumeIdentifier(String identifier, boolean originallyTerminal, boolean isTerminal, boolean allowReuse) {
355356
if ( !path.isEmpty() ) {
356357
path.append( '.' );
357358
}

hibernate-core/src/test/java/org/hibernate/orm/test/collection/basic/JoinFetchElementCollectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testJoinFetchesByPath(SessionFactoryScope scope) {
5858
session -> {
5959
final String qry = "SELECT user "
6060
+ "FROM User user "
61-
+ "LEFT OUTER JOIN FETCH user.contact "
61+
+ "JOIN FETCH user.contact "
6262
+ "LEFT OUTER JOIN FETCH user.contact.emailAddresses2 "
6363
+ "LEFT OUTER JOIN FETCH user.contact.emailAddresses";
6464
User user = (User) session.createQuery( qry ).uniqueResult();

hibernate-core/src/test/java/org/hibernate/orm/test/hql/FunctionNameAsColumnTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void testGetMultiColumnSameNameAsArgFunctionHQL(SessionFactoryScope sessi
106106
sessionFactory.inTransaction(s -> {
107107
EntityWithFunctionAsColumnHolder holder1 = (EntityWithFunctionAsColumnHolder) s.createQuery(
108108
"from EntityWithFunctionAsColumnHolder h left join fetch h.entityWithArgFunctionAsColumns " +
109-
"left join fetch h.nextHolder left join fetch h.nextHolder.entityWithArgFunctionAsColumns " +
109+
"join fetch h.nextHolder left join fetch h.nextHolder.entityWithArgFunctionAsColumns " +
110110
"where h.nextHolder is not null" )
111111
.uniqueResult();
112112
assertTrue( Hibernate.isInitialized( holder1.getEntityWithArgFunctionAsColumns() ) );
@@ -193,7 +193,7 @@ public void testGetMultiColumnSameNameAsNoArgFunctionHQL(SessionFactoryScope fac
193193
var hql = """
194194
from EntityWithFunctionAsColumnHolder h
195195
left join fetch h.entityWithNoArgFunctionAsColumns
196-
left join fetch h.nextHolder
196+
join fetch h.nextHolder
197197
left join fetch h.nextHolder.entityWithNoArgFunctionAsColumns
198198
where h.nextHolder is not null
199199
""";

0 commit comments

Comments
 (0)