DATAJPA-506 - Add support for conversion of Blob values to byte[] in native queries.

JpaQueryExecution no applies type conversion for Blob instances to be able to return byte[] from repository calls.

Original pull request: #72.
This commit is contained in:
Thomas Darimont
2014-05-16 17:09:06 +02:00
committed by Oliver Gierke
parent af45da40c6
commit 68e2ee5ed9
4 changed files with 133 additions and 1 deletions

View File

@@ -1390,6 +1390,23 @@ public class UserRepositoryTests {
flushTestUsers();
byte[] result = null; // repository.findBinaryDataByIdJpaQl(firstUser.getId());
assertThat(result.length, is(data.length));
assertThat(result, is(data));
}
/**
* @see DATAJPA-506
*/
@Test
public void findBinaryDataByIdNative() throws Exception {
byte[] data = "Woho!!".getBytes("UTF-8");
firstUser.setBinaryData(data);
flushTestUsers();
byte[] result = repository.findBinaryDataByIdNative(firstUser.getId());
assertThat(result.length, is(data.length));
assertThat(result, is(data));
}

View File

@@ -445,4 +445,10 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
* @see DATAJPA-551
*/
Slice<User> findTop2UsersBy(Pageable page);
/**
* @see DATAJPA-506
*/
@Query(value = "select u.binaryData from User u where u.id = ?", nativeQuery = true)
byte[] findBinaryDataByIdNative(Integer id);
}