HHH-11726 - PASS_DISTINCT_THROUGH hint is ignored when used in conjunction with maxResults/firstResult limiters
This commit is contained in:
parent
60f2ac8534
commit
2bb041423e
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,17 +103,38 @@ 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)
|
||||||
.getResultList();
|
.setMaxResults(5)
|
||||||
|
.getResultList();
|
||||||
assertEquals(1, persons.size());
|
assertEquals(1, persons.size());
|
||||||
String sqlQuery = sqlStatementInterceptor.getSqlQueries().getLast();
|
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")
|
@Entity(name = "Person")
|
||||||
|
|
Loading…
Reference in New Issue