|
6 | 6 | */
|
7 | 7 | package org.hibernate.test.hql;
|
8 | 8 |
|
| 9 | +import java.util.Collections; |
9 | 10 | import java.util.List;
|
10 | 11 | import javax.persistence.Entity;
|
11 | 12 | import javax.persistence.FetchType;
|
|
15 | 16 | import javax.persistence.Table;
|
16 | 17 |
|
17 | 18 | import org.hibernate.annotations.NaturalId;
|
| 19 | +import org.hibernate.engine.query.spi.HQLQueryPlan; |
| 20 | +import org.hibernate.hql.spi.QueryTranslator; |
| 21 | + |
18 | 22 | import org.hibernate.testing.TestForIssue;
|
19 | 23 | import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
20 | 24 | import org.junit.After;
|
|
23 | 27 |
|
24 | 28 | import static org.hamcrest.core.Is.is;
|
25 | 29 | import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
| 30 | +import static org.junit.Assert.assertEquals; |
| 31 | +import static org.junit.Assert.assertNotEquals; |
26 | 32 | import static org.junit.Assert.assertNull;
|
27 | 33 | import static org.junit.Assert.assertThat;
|
28 | 34 |
|
29 | 35 | /**
|
30 | 36 | * @author Steve Ebersole, Jan Martiska
|
| 37 | + * @author Christian Beikov |
31 | 38 | */
|
32 | 39 | public class EntityJoinTest extends BaseNonConfigCoreFunctionalTestCase {
|
33 | 40 | @Override
|
@@ -143,6 +150,29 @@ public void testJoinOnEntityJoinNode() {
|
143 | 150 | } );
|
144 | 151 | }
|
145 | 152 |
|
| 153 | + @Test |
| 154 | + @TestForIssue(jiraKey = "HHH-11538") |
| 155 | + public void testNoImpliedJoinGeneratedForEqualityComparison() { |
| 156 | + doInHibernate( this::sessionFactory, session -> { |
| 157 | + final HQLQueryPlan plan = sessionFactory().getQueryPlanCache().getHQLQueryPlan( |
| 158 | + "select r.id, cust.name " + |
| 159 | + "from FinancialRecord r " + |
| 160 | + " join Customer cust on r.customer = cust" + |
| 161 | + " order by r.id", |
| 162 | + false, |
| 163 | + Collections.EMPTY_MAP |
| 164 | + ); |
| 165 | + assertEquals( 1, plan.getTranslators().length ); |
| 166 | + final QueryTranslator translator = plan.getTranslators()[0]; |
| 167 | + final String generatedSql = translator.getSQLString(); |
| 168 | + |
| 169 | + int tableReferenceIndex = generatedSql.indexOf( " customer " ); |
| 170 | + assertNotEquals("Generated SQL doesn't contain a table reference for customer", -1, tableReferenceIndex ); |
| 171 | + int nextTableReferenceIndex = generatedSql.indexOf( " customer ", tableReferenceIndex + 1 ); |
| 172 | + assertEquals("Generated SQL wrongly joined customer twice", -1, nextTableReferenceIndex ); |
| 173 | + } ); |
| 174 | + } |
| 175 | + |
146 | 176 | @Test
|
147 | 177 | public void testRightOuterEntityJoins() {
|
148 | 178 | doInHibernate( this::sessionFactory, session -> {
|
|
0 commit comments