DATAJPA-342 - Corrected generated count projection from string queries.

The variable put into the count(…) clause of the generated query is now the original value except we find a DTO project or a count projection in the first place.
This commit is contained in:
Oliver Gierke
2013-05-07 14:01:25 +02:00
parent 31006e1866
commit d655862251
3 changed files with 41 additions and 13 deletions

View File

@@ -203,6 +203,16 @@ public class QueryUtilsUnitTests {
assertThat(applySorting(query, sort, "p"), endsWith("order by p.lastname asc, lower(p.firstname) asc"));
}
/**
* @see DATAJPA-342
*/
@Test
public void usesReturnedVariableInCOuntProjectionIfSet() {
assertCountQuery("select distinct m.genre from Media m where m.user = ?1 order by m.genre asc",
"select count(distinct m.genre) from Media m where m.user = ?1 order by m.genre asc");
}
private void assertCountQuery(String originalQuery, String countQuery) {
assertThat(createCountQueryFor(originalQuery), is(countQuery));
}