【发布时间】:2019-03-08 18:56:39
【问题描述】:
在 spring data jpa 查询的 where 子句中编写“hstore”类型列时遇到问题。
@Transactional(readOnly = true)
@Query(
value = "select ld from LocationData ld inner join fetch ld.assetData ad where ld.assetId in (:assetIds) and ld.orgId = :orgId and ld.eventTimestamp between :startDate and :endDate and ad.source in (:source) and
ad.attr -> 'CorrelationId' is not null",
countQuery = "select count(ld) from LocationData ld inner join ld.assetData ad where ld.assetId in (:assetIds) and ld.orgId = :orgId and ld.eventTimestamp between :startDate and :endDate and ad.source in (:source) and ad.attr -> 'CorrelationId' is not null""
)
Page<LocationData> findByAssetIdInAndOrgIdAndEventTimestampBetween(@Param("assetIds") List<Long> assetIds,
@Param("orgId") Integer orgId,
@Param("startDate") Long startEventTimestamp,
@Param("endDate") Long endEventTimeStamp,
@Param("source") List<String> source,
Pageable pageable);
在上面的查询中,“attr”是一个 hstore 类型的列。我在 attr 列中有一个名为 CorrelationId 的键。我想选择 CorrelationId 键不为空的那些。我尝试在 pgAdmin 中使用“ad.attr -> 'CorrelationId' is not null”,它工作得很好,但在 spring data jpa 查询中它不工作并抛出错误作为无效标识符。
谁能帮帮我。
【问题讨论】:
-
FIRST - 忘记 Spring、Hibernate、Java 或 (
insert_your_cool_development_environment_here)。使用psqlCLI(或您选择的 GUI 工具)运行原始查询 - 然后将其放入您的 IDE/框架中!如果查询在psql中有效,但在 spring 中无效,那么这是一个 IDE 问题。如果没有,将查询带回 dba.stackexchange,去掉 Java 代码!在添加新信息之前投票结束!
标签: postgresql postgresql-9.6 where hibernate hstore