Skip to content

Commit

Permalink
HHH-11337 - Incorrect SQL generated when use both left join with unre…
Browse files Browse the repository at this point in the history
…lated entity and implicit join to another entity in select-clause
  • Loading branch information
stasal authored and vladmihalcea committed Dec 14, 2016
1 parent f62d0d4 commit b2df137
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Expand Up @@ -402,7 +402,7 @@ protected void nestedFromFragment(AST d, AST parent) {
if ( right.getRealOrigin() == left ) {
// right represents a joins originating from left...
if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) {
out( ", " );
writeCrossJoinSeparator();
}
else {
out( " " );
Expand All @@ -411,7 +411,7 @@ protected void nestedFromFragment(AST d, AST parent) {
else {
// not so sure this is even valid subtree. but if it was, it'd
// represent two unrelated table references...
out( ", " );
writeCrossJoinSeparator();
}
}
out( d );
Expand Down
Expand Up @@ -15,6 +15,7 @@

import org.hibernate.Session;
import org.hibernate.annotations.NaturalId;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -108,6 +109,37 @@ public void testLeftOuterEntityJoins() {
}
}

@Test
@TestForIssue(jiraKey = "HHH-11337")
@SuppressWarnings("unchecked")
public void testLeftOuterEntityJoinsWithImplicitInnerJoinInSelectClause() {
Session session = openSession();
session.beginTransaction();

try {
// this should get all financial records even if their lastUpdateBy user is null
List<Object[]> result = session.createQuery(
"select r.id, u.id, u.username, r.customer.name " +
"from FinancialRecord r " +
" left join User u on r.lastUpdateBy = u.username" +
" order by r.id"
).list();
assertThat(result.size(), is(2));

Object[] stevesRecord = result.get(0);
assertThat(stevesRecord[0], is(1));
assertThat(stevesRecord[2], is("steve"));

Object[] noOnesRecord = result.get(1);
assertThat(noOnesRecord[0], is(2));
assertNull(noOnesRecord[2]);

} finally {
session.getTransaction().commit();
session.close();
}
}

@Test
@SuppressWarnings("unchecked")
public void testRightOuterEntityJoins() {
Expand Down

0 comments on commit b2df137

Please sign in to comment.