Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

DATAJPA-232 - Fixed parameter binding in SimpleJpaRepository.findAll(…

…Iterable<ID> ids).

We bound the given Iterable<ID> using List as parameter type which gets rejected if you hand in something that's not a List actually (e.g. HashSet). Changed parameter binding to hand in Iterable now.
  • Loading branch information...
commit 372ac4592268574e3d2a7132cc6cafff33b91d13 1 parent 42718c5
@olivergierke olivergierke authored
View
2  src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java
@@ -247,7 +247,7 @@ public boolean exists(ID id) {
return getQuery(new Specification<T>() {
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<?> path = root.get(entityInformation.getIdAttribute());
- return path.in(cb.parameter(List.class, "ids"));
+ return path.in(cb.parameter(Iterable.class, "ids"));
}
}, (Sort) null).setParameter("ids", ids).getResultList();
}
View
10 src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,6 +40,14 @@ public void findsAllByGivenIds() {
* Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 is resolved.
*/
@Override
+ public void handlesIterableOfIdsCorrectly() {
+
+ }
+
+ /**
+ * Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 is resolved.
+ */
+ @Override
public void allowsExecutingPageableMethodWithNullPageable() {
}
View
11 src/test/java/org/springframework/data/jpa/repository/OpenJpaNamespaceUserRepositoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,6 +56,13 @@ public void findsAllByGivenIds() {
}
+ /**
+ * Ignored until https://issues.apache.org/jira/browse/OPENJPA-2018 gets fixed.
+ */
+ @Override
+ public void handlesIterableOfIdsCorrectly() {
+ }
+
@Test
public void checkQueryValidationWithOpenJpa() {
@@ -98,4 +105,4 @@ public void queryUsingIn() {
List<User> resultList = query.getResultList();
assertThat(resultList.size(), is(2));
}
-}
+}
View
22 src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -31,6 +32,7 @@
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
+import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -850,6 +852,24 @@ public void executesNativeQueryForNonEntitiesCorrectly() {
assertThat(result, hasItem(1));
}
+ /**
+ * @see DATAJPA-232
+ */
+ @Test
+ public void handlesIterableOfIdsCorrectly() {
+
+ flushTestUsers();
+
+ Set<Integer> set = new HashSet<Integer>();
+ set.add(firstUser.getId());
+ set.add(secondUser.getId());
+
+ Iterable<User> result = repository.findAll(set);
+
+ assertThat(result, is(Matchers.<User> iterableWithSize(2)));
+ assertThat(result, hasItems(firstUser, secondUser));
+ }
+
protected void flushTestUsers() {
firstUser = repository.save(firstUser);
Please sign in to comment.
Something went wrong with that request. Please try again.