小编Geo*_*ser的帖子

jpa 标准 api 中 PostgreSQL 函数“jsonb_path_exists”的用法

我想使用 JPA 标准 api 调用 postgresql 函数jsonb_path_existshttps://www.postgresql.org/docs/12/functions-json.html)。

假设我有以下查询:

select id from person where jsonb_path_exists(person.json,'$.some_property[0].typ ? (@ =="Something")');
Run Code Online (Sandbox Code Playgroud)

通过 CriteriaBuilder 我会做类似的事情:

        var jsonQuery = jsonPath + " ? (@ ==\"" + value + "\")"; // evaluates to '$.some_property[0].typ ? (@ =="Something")'
        criteriaBuilder.function("jsonb_path_exists",
                        String.class,
                        entityRoot.get("json"),
                        criteriaBuilder.literal(jsonQuery)
                )
                .in(Boolean.TRUE);
Run Code Online (Sandbox Code Playgroud)

但是我还没有弄清楚如何将作为字符串提供的 jsonQuery 转换为 postgresjsonpath类型。因此我收到以下异常:

org.postgresql.util.PSQLException: ERROR: function jsonb_path_exists(jsonb, character varying) does not exist
Run Code Online (Sandbox Code Playgroud)

正确的签名是 jsonb_path_exists(target jsonb, path jsonpath [, vars jsonb [, silent bool]])

所有带有jsonpath参数的函数都存在此问题,例如jsonb_path_query …

postgresql jpa criteria-api

1
推荐指数
1
解决办法
1536
查看次数

标签 统计

criteria-api ×1

jpa ×1

postgresql ×1