I have a problem with writing criteria in java based on sql code, we must use JSON_TABLE function and search by parameters:
select tab1.id
from TABLE1 tab1
left join
TABLE2 param_json on tab1.id = param_json.TABLE_1_ID,
json_table(
param_json.PARAMS_JSON, '$[*]'
COLUMNS (
"paramCode" VARCHAR2(4000) PATH '$.paramCode',
"displayValue" VARCHAR2(4000) PATH '$.displayValue'
)
) jt
where jt."paramCode" = 'param1' and lower(jt."displayValue") like '%value%');
CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Long> query = builder.createQuery(Long.class);
Root<Table1> table1Root = query.from(Table1.class);
Join<Table1, Table2> jsonEJBJoin = table1Root.join(Table1_.table2Elements);
//how add json_table function
List<Predicate> whereConditions = new LinkedList<>();
Predicate[] predicates = new Predicate[whereConditions.size()];
//how add where conditions based on json_table function
query.where(whereConditions.toArray(predicates));
query.select(table1Root.get(Table1_.id));
List<Long> resultList = getEntityManager().createQuery(query)
.setMaxResults(10)
.getResultList();