DATAJPA-277 - Specification execution with sorting now uses left joins where necessary.
When applying sorting options to a Specification based query we have to make sure to apply left joins where necessary as we otherwise exclude results with null associations. Applying the sort options does an enhanced inspection of the target path and declares a left join instead of a get if the path logically points to an entity. The Metamodel API is not without caveats here, see http://bit.ly/10geC02.
This commit is contained in:
@@ -51,4 +51,8 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi
|
||||
public void allowsExecutingPageableMethodWithNullPageable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doesNotDropNullValuesOnPagedSpecificationExecution() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ import java.util.Set;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
@@ -948,6 +952,24 @@ public class UserRepositoryTests {
|
||||
assertThat(result.getContent(), hasSize((int) repository.count()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-277
|
||||
*/
|
||||
@Test
|
||||
public void doesNotDropNullValuesOnPagedSpecificationExecution() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
Page<User> page = repository.findAll(new Specification<User>() {
|
||||
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
||||
return cb.equal(root.get("lastname"), "Gierke");
|
||||
}
|
||||
}, new PageRequest(0, 20, new Sort("manager.lastname")));
|
||||
|
||||
assertThat(page.getNumberOfElements(), is(1));
|
||||
assertThat(page, hasItem(firstUser));
|
||||
}
|
||||
|
||||
private Page<User> executeSpecWithSort(Sort sort) {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
Reference in New Issue
Block a user