DATAJPA-510 - Fix regression when sorting by property of associated object.
The main problem was a bug in querydsl 3.3.2 that has been resolved resolved in querydsl 3.3.3 to which we just updated in in spring-data-build/#70. Cleaner usage of querydsl API and less brittle casting. Added test case for sorting by nested association property that is wrapped in a function, e.g. lower(…). Original pull request: #87.
This commit is contained in:
committed by
Oliver Gierke
parent
a39f69c0a6
commit
4d63856dde
@@ -31,10 +31,12 @@ import com.mysema.query.jpa.HQLTemplates;
|
||||
import com.mysema.query.jpa.JPQLQuery;
|
||||
import com.mysema.query.jpa.OpenJPATemplates;
|
||||
import com.mysema.query.jpa.impl.JPAQuery;
|
||||
import com.mysema.query.support.Expressions;
|
||||
import com.mysema.query.types.EntityPath;
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.OrderSpecifier.NullHandling;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
|
||||
/**
|
||||
@@ -224,9 +226,9 @@ public class Querydsl {
|
||||
|
||||
if (!path.hasNext() && order.isIgnoreCase()) {
|
||||
// if order is ignore-case we have to treat the last path segment as a String.
|
||||
sortPropertyExpression = ((PathBuilder<?>) sortPropertyExpression).getString(path.getSegment()).lower();
|
||||
sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower();
|
||||
} else {
|
||||
sortPropertyExpression = ((PathBuilder<?>) sortPropertyExpression).get(path.getSegment());
|
||||
sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
|
||||
}
|
||||
|
||||
path = path.next();
|
||||
|
||||
@@ -1281,6 +1281,24 @@ public class UserRepositoryTests {
|
||||
assertThat(page.getContent().get(3), is(firstUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-510
|
||||
*/
|
||||
@Test
|
||||
public void sortByNestedAssociationPropertyWithSortOrderIgnoreCaseInPageable() {
|
||||
|
||||
firstUser.setManager(thirdUser);
|
||||
thirdUser.setManager(fourthUser);
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
Page<User> page = repository.findAll(new PageRequest(0, 10, //
|
||||
new Sort(new Sort.Order(Direction.ASC, "manager.manager.firstname").ignoreCase())));
|
||||
|
||||
assertThat(page.getContent(), hasSize(4));
|
||||
assertThat(page.getContent().get(3), is(firstUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-496
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user