Skip to content

Commit

Permalink
DATAJPA-23 - Fixed query building for IsNull and IsNotNull.
Browse files Browse the repository at this point in the history
Use the actually accessed path instead of the root object. Added test cases to verify behaviour.
  • Loading branch information
odrotbohm committed Feb 14, 2011
1 parent e6e941b commit 23fd134
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ root.<Comparable> get(part.getProperty().toDotPath()),
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,31 @@ public void executesFindByColleaguesLastnameCorrectly() throws Exception {
}


@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,10 @@ List<User> findByFirstnameOrLastname(@Param("lastname") String lastname,


List<User> findByColleaguesLastname(String lastname);


List<User> findByLastnameNotNull();


List<User> findByLastnameNull();
}

0 comments on commit 23fd134

Please sign in to comment.