DATAJPA-23 - Fixed query building for IsNull and IsNotNull.
Use the actually accessed path instead of the root object. Added test cases to verify behaviour.
This commit is contained in:
@@ -175,9 +175,9 @@ public class JpaQueryCreator extends
|
||||
return builder.lessThan(getComparablePath(root, part),
|
||||
nextAsComparable(iterator));
|
||||
case IS_NULL:
|
||||
return root.isNull();
|
||||
return path.isNull();
|
||||
case IS_NOT_NULL:
|
||||
return root.isNotNull();
|
||||
return path.isNotNull();
|
||||
case LIKE:
|
||||
return builder.like(root.<String> get(part.getProperty()
|
||||
.toDotPath()), iterator.next().toString());
|
||||
|
||||
@@ -759,6 +759,31 @@ public class UserRepositoryTests {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void executesFindByNotNullLastnameCorrectly() throws Exception {
|
||||
|
||||
flushTestUsers();
|
||||
List<User> result = repository.findByLastnameNotNull();
|
||||
|
||||
assertThat(result.size(), is(3));
|
||||
assertThat(result, hasItems(firstUser, secondUser, thirdUser));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void executesFindByNullLastnameCorrectly() throws Exception {
|
||||
|
||||
flushTestUsers();
|
||||
User forthUser =
|
||||
repository.save(new User("Foo", null, "email@address.com"));
|
||||
|
||||
List<User> result = repository.findByLastnameNull();
|
||||
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result, hasItems(forthUser));
|
||||
}
|
||||
|
||||
|
||||
private Page<User> executeSpecWithSort(Sort sort) {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
@@ -190,4 +190,10 @@ public interface UserRepository extends JpaRepository<User, Integer>,
|
||||
|
||||
|
||||
List<User> findByColleaguesLastname(String lastname);
|
||||
|
||||
|
||||
List<User> findByLastnameNotNull();
|
||||
|
||||
|
||||
List<User> findByLastnameNull();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user