postgresql - 使用休眠规范搜索 json

时间:2021-02-20 05:44:12

标签: json postgresql hibernate search specifications

我在搜索 json 字段时遇到问题。任何帮助将不胜感激..这里是示例代码片段和我面临的错误

实体类

@TypeDef(name = "cardjsonb", typeClass = JsonBinaryType.class)
public class TransactionEntity {

    @Type(type = "cardjsonb")
    @Column(name = "card_details", columnDefinition = "jsonb")
    private TransactionCardDetails cardDetails;
}


public class TransactionCardDetails {

    private Date expiryDate; //MM-YYYY

    private String cardOnName;

    private String cardNumber;
}

规范片段

 return (root, query, builder) -> builder.equal(
                    builder.function("json_extract_path_text", JsonBinaryType.class, root.get("cardDetails"), builder.literal("cardOnName")),
                    builder.literal("David")
                );

错误详情

ERROR 20628 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: function json_extract_path_text(jsonb, character varying) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 1732

1 个答案:

答案 0 :(得分:0)

如果您使用 jsonb 作为输入,则需要改用 jsonb_extract_path_text 函数。