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:
Oliver Gierke
2011-02-14 17:54:37 +01:00
parent e6e941b40f
commit 23fd1349a3
3 changed files with 33 additions and 2 deletions

View File

@@ -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());

View File

@@ -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();

View File

@@ -190,4 +190,10 @@ public interface UserRepository extends JpaRepository<User, Integer>,
List<User> findByColleaguesLastname(String lastname);
List<User> findByLastnameNotNull();
List<User> findByLastnameNull();
}