postgresql - 如何在 Spring Boot JPA 中按 Posgres 的 json 属性排序?
问题描述
我写了一个@Query
inJPA
来按属性获取详细信息,json
这会导致错误。
@Query("SELECT t FROM Tcl order by t.equipment->>'eqpm_n' ASC")
public List<Tcl> getEquipmentList();
引起:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌
SELECT t FROM com.target.mpe.models.Tcl order by t.equipment->>'eqpm_n' ASC
同样的查询在 Postgres 控制台中运行良好。我怎样才能让它在 SpringBoot JPA 中工作?我需要尝试原生查询吗?
解决方案
JPQL 不支持这种 PostgreSQL 语法。您必须使用 nativeQuery:
@Query(value = "SELECT * FROM Tcl t order by t.equipment->>'eqpm_n' ASC", nativeQuery = true)
public List<Tcl> getEquipmentList();
推荐阅读
- intellij-plugin - 在 IntelliJ IDEA 插件中将捆绑插件声明为依赖项
- javascript - 我无法为我的柜台项目添加颜色
- python - 如何在 tkinter 画布中创建图像幻灯片?
- azure-data-factory-2 - 如何使用 GetMetadata 活动递归获取所有文件和文件夹
- node.js - 如何确保所有传入的请求都正确执行?
- python - 生成器没有在 Python 中创建任何输出
- javascript - 同时运行 Keyup 和 Keydown
- java - 我对 python 中的某些东西感到困惑,以发送我试图在 java 中重新创建的 HTTP 请求
- php - SQL查询,一对多,每个匹配的计数
- python - Pymongo - 如何返回特定字段?