Skip to content

Commit a82f966

Browse files
committed
HHH-18871 make use of explicitSqlAliasBase when creating table group
1 parent a9b955e commit a82f966

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,6 @@ private TableGroup createRootTableGroupJoin(
807807
SqlAstCreationState creationState) {
808808
final CollectionPersister collectionDescriptor = getCollectionDescriptor();
809809
final SqlAstJoinType joinType = determineSqlJoinType( lhs, requestedJoinType, fetched );
810-
final SqlAliasBase sqlAliasBase = creationState.getSqlAliasBaseGenerator().createSqlAliasBase( getSqlAliasStem() );
811810

812811
final TableGroup tableGroup;
813812
if ( collectionDescriptor.isOneToMany() ) {
@@ -818,7 +817,7 @@ private TableGroup createRootTableGroupJoin(
818817
fetched,
819818
addsPredicate,
820819
explicitSourceAlias,
821-
sqlAliasBase,
820+
explicitSqlAliasBase,
822821
creationState
823822
);
824823
}
@@ -830,7 +829,7 @@ private TableGroup createRootTableGroupJoin(
830829
fetched,
831830
addsPredicate,
832831
explicitSourceAlias,
833-
sqlAliasBase,
832+
explicitSqlAliasBase,
834833
creationState
835834
);
836835
}

hibernate-core/src/test/java/org/hibernate/orm/test/query/NativeQueryNestedTree.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,43 @@ public void test(SessionFactoryScope scope) {
4949
.list()
5050
)
5151
);
52+
53+
assertDoesNotThrow(() ->
54+
scope.inTransaction(session ->
55+
session.createNativeQuery("""
56+
SELECT {t.*}, {t2.*}, {t3.*}, {t4.*}
57+
FROM tree t
58+
INNER JOIN tree t2 ON t2.parentident = t.ident
59+
INNER JOIN tree t3 ON t3.parentident = t2.ident
60+
INNER JOIN tree t4 ON t4.parentident = t3.ident
61+
""")
62+
.addEntity("t", TreeNode.class)
63+
.addJoin("t2", "t.children")
64+
.addJoin("t3", "t2.children")
65+
.addJoin("t4", "t3.children")
66+
.list()
67+
)
68+
);
69+
70+
// Let's get crazy
71+
assertDoesNotThrow(() ->
72+
scope.inTransaction(session ->
73+
session.createNativeQuery("""
74+
SELECT {t.*}, {t2.*}, {t3.*}, {t4.*}, {t5.*}
75+
FROM tree t
76+
INNER JOIN tree t2 ON t2.parentident = t.ident
77+
INNER JOIN tree t3 ON t3.parentident = t2.ident
78+
INNER JOIN tree t4 ON t4.parentident = t3.ident
79+
INNER JOIN tree t5 ON t5.parentident = t4.ident
80+
""")
81+
.addEntity("t", TreeNode.class)
82+
.addJoin("t2", "t.children")
83+
.addJoin("t3", "t2.children")
84+
.addJoin("t4", "t3.children")
85+
.addJoin("t5", "t4.children")
86+
.list()
87+
)
88+
);
5289
}
5390

5491
@Entity(name = "TreeNode")

0 commit comments

Comments
 (0)