【问题标题】:JPA Repository Lob columnJPA 存储库 Lob 列
【发布时间】:2018-01-26 03:05:45
【问题描述】:

是否可以通过lob-column过滤来实现JPA-repository?

我有以下代码:

@Entity
@Table(name = "SUBJECT_IDENTIFIER")      
public class SubjectIdentifier implements Serializable {

     @Id
     @Column(name = "SUBJECT_IDENTIFIER_ID")
     private long subjectIdentifierIid;

     @Lob
     @Column(name = "SOR_BP_GUID", columnDefinition="BLOB NOT NULL")
     private byte[] bpGuid;

     //getter/setter
}


public interface SubjectIdentifierRepository extends JpaRepository<SubjectIdentifier, Long> {

   @Query("select si from SubjectIdentifier  si where si.bpGuid= :bpGuid")
   SubjectRepository findByBpGuid(@Param("bpGuid") byte[] bpGuid);

}

//测试

SubjectRepository byBpGuid = subjectIdentifierRepository.findByBpGuid("D9E70D24567E4DAE8FD3ED5898579092".getBytes());

但我无法从数据库中找到对象。 我是否必须通过其他方式实现此查询?

【问题讨论】:

  • 您的列名(在数据库中,并在注释中定义)是 SOR_BP_GUID 但您的 SQL 语句正在寻找 si.bpGuid - 我认为它应该是 si.sor_bp_guid

标签: java spring spring-data spring-data-jpa jpql


【解决方案1】:

当然,前提是您的数据库支持它。

我建议您编写如下所示的查询,因为无需使用@Query 注释即可完全解决该要求。

SubjectRepository findOneByBpGuid(@Param("bpGuid") byte[] bs);

我对@9​​87654324@ 规范有点好奇:如果没有那个,db 列是否设置为错误的类型?如果可能的话,我更喜欢这个声明而不是使用columnDefinition。这将使配置数据库不可知。

@Column(name = "SOR_BP_GUID", nullable = false)

另请参阅:https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    相关资源
    最近更新 更多