Home @Query JPA returning a blob
Reply: 2

@Query JPA returning a blob

Tyvain Published in 2017-10-18 02:16:15Z

Can't figure out how to retreive a 'blob' type from my DB. Can't figure out how to do in JPA.

public interface ActeRepository extends JpaRepository<byte[], String> {
    @Query(value = "select doc from t_doc_content", nativeQuery = true)
    public List<byte[]> findActeByBordereau(String id);


Caused by: java.lang.IllegalArgumentException: Not an managed type: class [B at org.hibernate.jpa.internal.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:219) at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.(JpaMetamodelEntityInformation.java:68) at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:67) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:152) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:99) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:81) at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ... 29 common frames omitted

Any idea ?

Scary Wombat
Scary Wombat Reply to 2017-10-18 02:24:18Z

The definition of your interface is not correct

Maybe change to

public interface ActeRepository extends JpaRepository< Acte, String> {

Is the primary key a String, if so the above is OK, else change String to whatever it is. Long ?

Bobernac Alexandru
Bobernac Alexandru Reply to 2017-10-18 08:59:02Z

This is not the way JpaRepository works, when extending it you need to remember that it is of type JpaRepository<T, ID extends Serializable>, where T is a POJO that you mapped as a table in the database maybe using @Entity and the ID is you primary key of that table, Long or Integer, I doubt you have a String as your primary key as integers are faster to index. I dont't know the rest of your code but to give you an example:

public class File {

@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;

private byte[] bytes;

@JoinColumn(name = "user_id")
private User user;

public File() {

public File(String name, byte[] bytes, User user) {
    this.name = name;
    this.bytes = bytes;
    this.user = user;

public Long getId() {
    return id;

public void setId(Long id) {
    this.id = id;

public String getName() {
    return name;

public void setName(String name) {
    this.name = name;

public byte[] getBytes() {
    return bytes;

public void setBytes(byte[] bytes) {
    this.bytes = bytes;

public User getUser() {
    return user;

public void setUser(User user) {
    this.user = user;

public interface FileRepository extends JpaRepository<File, Long>{

List<File> findByName(String name);

And after you get a list of objects, you get that bytes variable from each object.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.297255 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO