我在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查询中,它不工作,并作为无效标识符抛出错误。
有人能帮我吗。
1条答案
按热度按时间jgwigjjp1#
如果JPA不喜欢“->”操作符,您可以尝试函数式表单
字符串
或者是
型