2017-10-18 19 views
0

DBから「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> { 

に変更

正しくありませんので、上記のことが何であれにOK、それ以外の変更Stringある場合、主キーの文字列です。長いです ?

0

これはJpaRepository作品方法ではありません、それを拡張するとき、あなたはそれがTはあなたが多分@Entityを使用して、データベース内のテーブルとしてマッピングPOJOで、IDはあなたが主キーであるタイプJpaRepository<T, ID extends Serializable>、であることを覚えておく必要がありますそのテーブルのLongまたはIntegerの場合、整数がインデックス化される方が速いため、主キーとして文字列があるとは限りません。

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

をそして、あなたは、オブジェクトのリストを取得した後、あなたはそれは、各オブジェクトから変数をバイト取得:私はあなたのコードの残りの部分を知っているが、あなたの例を与えることをdont't。

関連する問題