HHH-11337 - Incorrect SQL generated when use both left join with unrelated entity and implicit join to another entity in select-clause
(cherry picked from commit b2df137ed6
)
This commit is contained in:
parent
951cc68a3e
commit
d6ecc37c0f
|
@ -397,7 +397,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
if ( right.getRealOrigin() == left ) {
|
||||
// right represents a joins originating from left...
|
||||
if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) {
|
||||
out( ", " );
|
||||
writeCrossJoinSeparator();
|
||||
}
|
||||
else {
|
||||
out( " " );
|
||||
|
@ -406,7 +406,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
else {
|
||||
// not so sure this is even valid subtree. but if it was, it'd
|
||||
// represent two unrelated table references...
|
||||
out( ", " );
|
||||
writeCrossJoinSeparator();
|
||||
}
|
||||
}
|
||||
out( d );
|
||||
|
|
|
@ -15,6 +15,7 @@ import javax.persistence.Table;
|
|||
|
||||
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;
|
||||
|
@ -108,6 +109,37 @@ public class EntityJoinTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@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() {
|
||||
|
|
Loading…
Reference in New Issue