【问题标题】:How to use IN clause in JPA?如何在 JPA 中使用 IN 子句?
【发布时间】:2016-11-07 10:44:52
【问题描述】:

我正在使用 JPA 从带有 in 子句的表中获取结果,但遇到以下异常:

ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Fail to convert to internal representation

PFB 我的代码:

public interface ObjectCommonDao extends JpaRepository<ObjectCommon, Long> {

    @Query("select oc from ObjectCommon oc where oc.id in :listObjects")
    List<ObjectCommon> getListSelectedObject(@Param("listObjects") List<Long> listSelected);

}

请告诉我如何在上述查询中使用 IN 子句来获取行列表。

【问题讨论】:

  • ObjectCommon 的 'id' 字段是否定义为 Long?
  • 发布实体,以及异常的完整堆栈跟踪
  • 是的。 ID 字段很长。

标签: hibernate jpa


【解决方案1】:

试试这个

select oc from ObjectCommon oc where oc.id in (:listObjects)

【讨论】:

    猜你喜欢
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多