我正在尝试创建按json列表在列表中搜索的JPA规范
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder builder) {
Expression<String> unitsNames = builder.function("json_array_elements", String.class,
root.<String>get("unitsNames"));
return builder.function("json_extract_path_text", String.class,
unitsNames, builder.literal("en"))
.in(this.unitsNames);
}
我有例外:
Internal Exception: org.postgresql.util.PSQLException:
ERROR: set-returning functions are not allowed in WHERE
Json Array应该类似于
[{"en":"D1","ar":"D1"},{"en":"D2","ar":"D2"}]
和UnitArray:
D1 , D2
当尝试将其用作sql时,它的作用类似于
SELECT *
FROM TABLENAME
inner join json_array_elements(unitNames) data
on ((json_extract_path_text(data, 'en')) in ('D1'));
效果很好,但我不知道如何在postgres条件API中使用别名