I investigated the Value value search of JSON type column using JPA, so as a share. Case to search by Specification.
Use MySQL functions.
JSON_EXTRACT
SELECT * FROM ATABLE WHERE JSON_EXTRACT("column_name", "$.key") = value;
So, when using Spring JPA Specification,
public Specification<T> jsonSearch(String key, String val) {
return (root, query, cb) -> {
return cb.like(cb.function("JSON_EXTRACT", String.class, root.get("names"), cb.literal("$." + key)),
"%" + val + "%");
};
}
Custom expression in JPA CriteriaBuilder
Recommended Posts