[英]How to pass List of strings as parameter to JPA native query and substitute the same in Postgresql ARRAY[]
我有一个看起来像这样的 JPA 本机查询
@Query(
value = "SELECT * FROM feature f where jsonb_exists_any(f.feature_json -> 'properties' -> 'ids', array[:ids])",
nativeQuery = true)
feature_json 是一个 jsonb 列,并且:ids 是我需要传递给查询的输入参数,它是一个 UUID 字符串列表
带有样本值的查询如下
SELECT * FROM feature f where jsonb_exists_any(f.feature_json -> 'properties' -> 'ids', array['79eeb7ae-c2d0-3344-a6f5-eb424b820d03','a14bdb38-cedb-3743-bd50-9562ed2856b2'])
当我将上述值作为 Java 中的字符串列表传递时,查询无法执行,因为:ids 中的值被替换为(79eeb7ae-c2d0-3344-a6f5-eb424b820d03,a14bdb38-cedb-3743-bd50-9562ed2856b2)
所需'79eeb7ae-c2d0-3344-a6f5-eb424b820d03','a14bdb38-cedb-3743-bd50-9562ed2856b2'
我还尝试将此引用的逗号分隔值作为字符串传递给:ids 参数,查询执行时没有任何错误,但不获取任何结果。
如上所述,如何将来自 Java 的 uuid 字符串列表作为参数传递给本机查询?
更新:
我将查询修改如下:
@Query(
value = "SELECT * FROM feature f where jsonb_exists_any(f.feature_json -> 'properties' -> 'ids', :ids)",
nativeQuery = true)
List<FeatureEntity> getFeaturesByIds(@Param("ids") TypedParameterValue ids);
并从调用 function 中传入new TypedParameterValue(StringArrayType.INSTANCE, stringArray)
stringArray
在查询执行期间被转换为 postgresql 文本数组,查询返回预期响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.