2017-10-18 132 views
0

無法弄清楚如何從我的數據庫中檢索「blob」類型。無法弄清楚如何在JPA中做。@Query JPA返回blob

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

任何想法?

回答

0

您接口的定義是不正確的

也許改變

public interface ActeRepository extends JpaRepository< Acte, String> { 

是主鍵的字符串,如果有以上就是不管它是好,否則改變String。長 ?

0

這不是JpaRepository作品,延長它的時候,你需要記住,這是JpaRepository<T, ID extends Serializable>類型,其中T是你映射爲數據庫中的表一個POJO也許使用@Entity的方式和ID是你的主鍵的表,LongInteger,我懷疑你有一個字符串作爲你的主鍵,因爲整數更快的索引。我dont't知道你的代碼的其餘部分,但給你一個例子:

@Entity 
public class File { 

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

@Lob 
private byte[] bytes; 

@ManyToOne 
@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; 
} 
} 

@Repository 
public interface FileRepository extends JpaRepository<File, Long>{ 

List<File> findByName(String name); 
} 

,你會得到對象的列表之後,你從每個對象中的字節變量。