diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 4ba254e14..6dc74bddb 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -247,7 +247,7 @@ public class SimpleJpaRepository implements JpaRepos return getQuery(new Specification() { public Predicate toPredicate(Root 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(); } diff --git a/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java index f96ae716b..3117eb5b8 100644 --- a/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java +++ b/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. @@ -36,6 +36,14 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi } + /** + * 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. */ diff --git a/src/test/java/org/springframework/data/jpa/repository/OpenJpaNamespaceUserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/OpenJpaNamespaceUserRepositoryTests.java index c3ad79a4f..05cabbda7 100644 --- a/src/test/java/org/springframework/data/jpa/repository/OpenJpaNamespaceUserRepositoryTests.java +++ b/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 class OpenJpaNamespaceUserRepositoryTests extends NamespaceUserRepository } + /** + * 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 class OpenJpaNamespaceUserRepositoryTests extends NamespaceUserRepository List resultList = query.getResultList(); assertThat(resultList.size(), is(2)); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index b4de92d66..d8c7c8078 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/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 static org.springframework.data.jpa.domain.sample.UserSpecifications.*; 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.EntityManager; 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 class UserRepositoryTests { assertThat(result, hasItem(1)); } + /** + * @see DATAJPA-232 + */ + @Test + public void handlesIterableOfIdsCorrectly() { + + flushTestUsers(); + + Set set = new HashSet(); + set.add(firstUser.getId()); + set.add(secondUser.getId()); + + Iterable result = repository.findAll(set); + + assertThat(result, is(Matchers. iterableWithSize(2))); + assertThat(result, hasItems(firstUser, secondUser)); + } + protected void flushTestUsers() { firstUser = repository.save(firstUser);