I'm trying to implement search by inner json field. My entity looks like this:
@Data
@Entity
@Table(name = "restaurants")
@EqualsAndHashCode(callSuper = true)
public class Restaurant extends BaseEntity {
@Convert(converter = AddressConverter.class)
private Address address;
}
The address itself has city field inside. Now i'm trying to create specification:
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(
criteriaBuilder.function("jsonb_extract_path_text", String.class, root.get("address"),
criteriaBuilder.literal("city")), value)
And this is the error i have:
Caused by: org.postgresql.util.PSQLException: ERROR: function jsonb_extract_path_text(character varying, character varying) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 420
I read the postgres docs and the arguments for function ara json and array of texts:
json_extract_path_text(from_json json, VARIADIC path_elems text[])
Meanwhile in my case both arguments are character varying. What i'm doing wrong? Is there a way to cast the first argument into json object? I'm using latest postgresql 13.