【发布时间】:2017-07-28 16:30:12
【问题描述】:
我创建了一个休眠 userTypeData 并成功地将我的对象(称为“数据”)映射到 postgres 表中的 jsonb 数据类型。现在,我尝试使用 JpaRepository 来查询该 jsonb 列但没有成功。这是我用于查询的代码:
public interface GenieEntityDao extends JpaRepository<GenieEntity, Long>, QueryByExampleExecutor<GenieEntity> {
@Query(value = "SELECT e FROM from genie_entities e WHERE e.data ->> 'temp' = '30'", nativeQuery = true)
public List<GenieEntity> findByTempBiggerThan(String temp);
}
这是我得到的例外:
org.springframework.dao.InvalidDataAccessApiUsageException: Unknown parameter position: 1; nested exception is java.lang.IllegalArgumentException: Unknown parameter position: 1
有人知道如何使用@Query 注解查询 jsonb 列吗?
【问题讨论】:
-
如果你有 spring-data 方法参数,你应该在查询字符串中使用参数占位符(
:temp,或?)。
标签: postgresql spring-data-jpa