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.
This commit is contained in:
@@ -247,7 +247,7 @@ public class SimpleJpaRepository<T, ID extends Serializable> implements JpaRepos
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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<User> resultList = query.getResultList();
|
||||
assertThat(resultList.size(), is(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
Reference in New Issue
Block a user