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.processedSQL = this.processedSQL;
copy.processedPositionalParameterTypes = this.processedPositionalParameterTypes; copy.processedPositionalParameterTypes = this.processedPositionalParameterTypes;
copy.processedPositionalParameterValues = this.processedPositionalParameterValues; copy.processedPositionalParameterValues = this.processedPositionalParameterValues;
copy.passDistinctThrough = this.passDistinctThrough;
return copy; return copy;
} }

View File

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