DATAJPA-433 - Fix IN expressions for non empty collections in EclipseLink.
We now convert parameter to collections and use `ParameterExpression<Collection<?>>` to declare the parameter. This utilises the fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477. It does break empty collections in EclipseLink which so far worked in 2.6 but didn't work 2.7 but support for only empty collection isn't of much use. Original pull request: #185.
This commit is contained in:
committed by
Jens Schauder
parent
bbb01685cd
commit
48e947dffb
@@ -53,6 +53,7 @@ import org.springframework.util.Assert;
|
||||
* @author Michael Cramer
|
||||
* @author Mark Paluch
|
||||
* @author Reda.Housni-Alaoui
|
||||
* @author Moritz Becker
|
||||
*/
|
||||
public class JpaQueryCreator extends AbstractQueryCreator<CriteriaQuery<? extends Object>, Predicate> {
|
||||
|
||||
@@ -268,9 +269,11 @@ public class JpaQueryCreator extends AbstractQueryCreator<CriteriaQuery<? extend
|
||||
case IS_NOT_NULL:
|
||||
return getTypedPath(root, part).isNotNull();
|
||||
case NOT_IN:
|
||||
return getTypedPath(root, part).in(provider.next(part, Collection.class).getExpression()).not();
|
||||
// cast required for eclipselink workaround, see DATAJPA-433
|
||||
return getTypedPath(root, part).in((Expression<Collection<?>>) provider.next(part, Collection.class).getExpression()).not();
|
||||
case IN:
|
||||
return getTypedPath(root, part).in(provider.next(part, Collection.class).getExpression());
|
||||
// cast required for eclipselink workaround, see DATAJPA-433
|
||||
return getTypedPath(root, part).in((Expression<Collection<?>>) provider.next(part, Collection.class).getExpression());
|
||||
case STARTING_WITH:
|
||||
case ENDING_WITH:
|
||||
case CONTAINING:
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.jpa.repository.support;
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -69,6 +70,7 @@ import org.springframework.util.Assert;
|
||||
* @author Stefan Fussenegger
|
||||
* @author Jens Schauder
|
||||
* @author David Madden
|
||||
* @author Moritz Becker
|
||||
* @param <T> the type of the entity to handle
|
||||
* @param <ID> the type of the entity's identifier
|
||||
*/
|
||||
@@ -347,10 +349,16 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
||||
return results;
|
||||
}
|
||||
|
||||
// required for eclipselink workaround, see DATAJPA-433
|
||||
List<ID> idCollection = new ArrayList<ID>();
|
||||
for (ID id : ids) {
|
||||
idCollection.add(id);
|
||||
}
|
||||
|
||||
ByIdsSpecification<T> specification = new ByIdsSpecification<T>(entityInformation);
|
||||
TypedQuery<T> query = getQuery(specification, Sort.unsorted());
|
||||
|
||||
return query.setParameter(specification.parameter, ids).getResultList();
|
||||
return query.setParameter(specification.parameter, idCollection).getResultList();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -778,7 +786,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
||||
|
||||
private final JpaEntityInformation<T, ?> entityInformation;
|
||||
|
||||
@Nullable ParameterExpression<Iterable> parameter;
|
||||
@Nullable ParameterExpression<Collection<?>> parameter;
|
||||
|
||||
ByIdsSpecification(JpaEntityInformation<T, ?> entityInformation) {
|
||||
this.entityInformation = entityInformation;
|
||||
@@ -791,7 +799,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
||||
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
||||
|
||||
Path<?> path = root.get(entityInformation.getIdAttribute());
|
||||
parameter = cb.parameter(Iterable.class);
|
||||
parameter = (ParameterExpression<Collection<?>>) (ParameterExpression) cb.parameter(Collection.class);
|
||||
return path.in(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,37 +33,17 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Jens Schauder
|
||||
* @author Moritz Becker
|
||||
*/
|
||||
@ContextConfiguration(value = "classpath:eclipselink.xml")
|
||||
public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserRepositoryTests {
|
||||
|
||||
/**
|
||||
* Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 is resolved.
|
||||
*/
|
||||
@Override
|
||||
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 invokesQueryWithVarargsParametersCorrectly() {}
|
||||
|
||||
/**
|
||||
* Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=422450 is resolved.
|
||||
*/
|
||||
@Override
|
||||
public void sortByAssociationPropertyShouldUseLeftOuterJoin() {}
|
||||
public void sortByAssociationPropertyShouldUseLeftOuterJoin() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=422450 is resolved.
|
||||
@@ -123,56 +103,29 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi
|
||||
public void bindsNativeQueryResultsToProjectionByName() {}
|
||||
|
||||
/**
|
||||
* Ignores the test for EclipseLink 2.7.2. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is
|
||||
* fixed.
|
||||
* Ignores the test. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is fixed.
|
||||
*/
|
||||
@Override
|
||||
@Test // DATAJPA-1314
|
||||
public void findByEmptyArrayOfIntegers() throws Exception {
|
||||
|
||||
assumeNotEclipseLink2_7_2plus();
|
||||
|
||||
super.findByEmptyArrayOfIntegers();
|
||||
}
|
||||
public void findByEmptyArrayOfIntegers() throws Exception {}
|
||||
|
||||
/**
|
||||
* Ignores the test for EclipseLink 2.7.2. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is
|
||||
* fixed.
|
||||
* Ignores the test. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is fixed.
|
||||
*/
|
||||
@Override
|
||||
@Test // DATAJPA-1314
|
||||
public void findByAgeWithEmptyArrayOfIntegersOrFirstName() {
|
||||
|
||||
assumeNotEclipseLink2_7_2plus();
|
||||
|
||||
super.findByAgeWithEmptyArrayOfIntegersOrFirstName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores the test for EclipseLink 2.7.2. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is
|
||||
* fixed.
|
||||
* Ignores the test. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is fixed.
|
||||
*/
|
||||
@Override
|
||||
@Test // DATAJPA-1314
|
||||
public void findByEmptyCollectionOfIntegers() throws Exception {
|
||||
|
||||
assumeNotEclipseLink2_7_2plus();
|
||||
|
||||
super.findByEmptyCollectionOfIntegers();
|
||||
}
|
||||
public void findByEmptyCollectionOfIntegers() throws Exception {}
|
||||
|
||||
/**
|
||||
* Ignores the test for EclipseLink 2.7.2. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is
|
||||
* fixed.
|
||||
* Ignores the test. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is fixed.
|
||||
*/
|
||||
@Override
|
||||
@Test // DATAJPA-1314
|
||||
public void findByEmptyCollectionOfStrings() throws Exception {
|
||||
|
||||
assumeNotEclipseLink2_7_2plus();
|
||||
|
||||
super.findByEmptyCollectionOfStrings();
|
||||
}
|
||||
public void findByEmptyCollectionOfStrings() throws Exception {}
|
||||
|
||||
/**
|
||||
* Ignores the test for EclipseLink.
|
||||
@@ -181,10 +134,4 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi
|
||||
@Test
|
||||
@Ignore
|
||||
public void savingUserThrowsAnException() {}
|
||||
|
||||
private void assumeNotEclipseLink2_7_2plus() {
|
||||
|
||||
Assume.assumeFalse("Empty collections seem to be broken in EclipseLink 2.7.2+",
|
||||
Version.parse(getVersion()).isGreaterThanOrEqualTo(new Version(2, 7, 2)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user