HHH-11726 - PASS_DISTINCT_THROUGH hint is ignored when used in conjunction with maxResults/firstResult limiters

This commit is contained in:
jonathan 2017-07-02 21:59:41 -05:00 committed by Vlad Mihalcea
parent 60f2ac8534
commit 2bb041423e
2 changed files with 37 additions and 7 deletions

View File

@ -652,6 +652,7 @@ public final class QueryParameters {
copy.processedSQL = this.processedSQL;
copy.processedPositionalParameterTypes = this.processedPositionalParameterTypes;
copy.processedPositionalParameterValues = this.processedPositionalParameterValues;
copy.passDistinctThrough = this.passDistinctThrough;
return copy;
}

View File

@ -49,8 +49,7 @@ public class SelectDistinctHqlTest extends BaseNonConfigCoreFunctionalTestCase {
};
}
@Test
public void test() {
protected void prepareTest() {
doInHibernate( this::sessionFactory, session -> {
Person person = new Person();
person.id = 1L;
@ -59,6 +58,15 @@ public class SelectDistinctHqlTest extends BaseNonConfigCoreFunctionalTestCase {
person.addPhone( new Phone( "027-123-4567" ) );
person.addPhone( new Phone( "028-234-9876" ) );
} );
}
@Override
protected boolean isCleanupTestDataRequired() {
return true;
}
@Test
public void test() {
doInHibernate( this::sessionFactory, session -> {
sqlStatementInterceptor.getSqlQueries().clear();
@ -95,17 +103,38 @@ public class SelectDistinctHqlTest extends BaseNonConfigCoreFunctionalTestCase {
String sqlQuery = sqlStatementInterceptor.getSqlQueries().getLast();
assertTrue( sqlQuery.contains( " distinct " ) );
} );
}
@Test
@TestForIssue( jiraKey = "HHH-11726" )
public void testDistinctPassThroughFalse() {
doInHibernate( this::sessionFactory, session -> {
sqlStatementInterceptor.getSqlQueries().clear();
List<Person> persons = session.createQuery(
"select distinct p from Person p left join fetch p.phones " )
.setHint( QueryHints.HINT_PASS_DISTINCT_THROUGH, false )
.getResultList();
"select distinct p from Person p left join fetch p.phones ")
.setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, false)
.setMaxResults(5)
.getResultList();
assertEquals(1, persons.size());
String sqlQuery = sqlStatementInterceptor.getSqlQueries().getLast();
assertFalse( sqlQuery.contains( " distinct " ) );
} );
assertFalse(sqlQuery.contains(" distinct "));
});
}
@Test
@TestForIssue( jiraKey = "HHH-11726" )
public void testDistinctPassThroughTrue() {
doInHibernate( this::sessionFactory, session -> {
sqlStatementInterceptor.getSqlQueries().clear();
List<Person> persons = session.createQuery(
"select distinct p from Person p left join fetch p.phones ")
.setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, true)
.setMaxResults(5)
.getResultList();
assertEquals(1, persons.size());
String sqlQuery = sqlStatementInterceptor.getSqlQueries().getLast();
assertTrue(sqlQuery.contains(" distinct "));
});
}
@Entity(name = "Person")