DATAJPA-505 - Projections for basic primitive arrays should use SingleEntityExecution.
We now execute a query as a SingleEntityExecution if the return-type of the particular query-method is an basic char[],Character[], byte[], Byte[]. Previously we tried to do an CollectionExecution which didn't return all elements of the actual result (e.g. the byte[]). Although EclipseLink and Hibernate support the use of array elements in projections OpenJPA seems not to. Filed https://issues.apache.org/jira/browse/OPENJPA-2484 to track the issue. Since OpenJPA prevents the bootstrap of the whole test suite I had to comment the query method + tests out. Tested Hibernate / EclipseLink by temporarily excluding all OpenJPA tests from the test-suite. Original pull request: #71.
This commit is contained in:
committed by
Oliver Gierke
parent
ae03311af2
commit
b78a89d7d9
@@ -20,7 +20,10 @@ import static org.springframework.core.annotation.AnnotationUtils.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.LockModeType;
|
||||
import javax.persistence.QueryHint;
|
||||
@@ -47,6 +50,20 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class JpaQueryMethod extends QueryMethod {
|
||||
|
||||
// @see JPA 2.0 Specification 2.2 Persistent Fields and Properties Page 23 - Top paragraph.
|
||||
private static final Set<Class<?>> NATIVE_ARRAY_TYPES;
|
||||
|
||||
static {
|
||||
|
||||
Set<Class<?>> types = new HashSet<Class<?>>(4);
|
||||
types.add(byte[].class);
|
||||
types.add(Byte[].class);
|
||||
types.add(char[].class);
|
||||
types.add(Character[].class);
|
||||
|
||||
NATIVE_ARRAY_TYPES = Collections.unmodifiableSet(types);
|
||||
}
|
||||
|
||||
private final QueryExtractor extractor;
|
||||
private final Method method;
|
||||
|
||||
@@ -275,4 +292,13 @@ public class JpaQueryMethod extends QueryMethod {
|
||||
public JpaParameters getParameters() {
|
||||
return (JpaParameters) super.getParameters();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryMethod#isCollectionQuery()
|
||||
*/
|
||||
@Override
|
||||
public boolean isCollectionQuery() {
|
||||
return super.isCollectionQuery() && !NATIVE_ARRAY_TYPES.contains(method.getReturnType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1214,6 +1214,7 @@ public class UserRepositoryTests {
|
||||
List<User> result = repository.findByBinaryData(data);
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, hasItem(firstUser));
|
||||
assertThat(result.get(0).getBinaryData(), is(data));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1279,6 +1280,24 @@ public class UserRepositoryTests {
|
||||
assertThat(result, hasSize(2));
|
||||
assertThat(result, hasItems(firstUser, secondUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-505
|
||||
* @see https://issues.apache.org/jira/browse/OPENJPA-2484
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void findBinaryDataByIdJpaQl() throws Exception {
|
||||
|
||||
byte[] data = "Woho!!".getBytes("UTF-8");
|
||||
firstUser.setBinaryData(data);
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
byte[] result = null; // repository.findBinaryDataByIdJpaQl(firstUser.getId());
|
||||
assertThat(result.length, is(data.length));
|
||||
assertThat(result, is(data));
|
||||
}
|
||||
|
||||
private Page<User> executeSpecWithSort(Sort sort) {
|
||||
|
||||
|
||||
@@ -311,4 +311,11 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
|
||||
* @see DATAJPA-496
|
||||
*/
|
||||
List<User> findByAttributesIn(Set<String> attributes);
|
||||
|
||||
/**
|
||||
* @see DATAJPA-505
|
||||
* @see https://issues.apache.org/jira/browse/OPENJPA-2484
|
||||
*/
|
||||
// @Query(value = "select u.binaryData from User u where u.id = :id")
|
||||
// byte[] findBinaryDataByIdJpaQl(@Param("id") Integer id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user