【发布时间】:2021-02-03 09:26:49
【问题描述】:
我有一个条件查询和一个子查询,我想将条件查询的限制应用于子查询。以下是我迄今为止尝试过的。
CriteriaQuery<Object> query = cb.createQuery(Object.class);
Root<Entity1> entityRoot = query.from(Entity1.class);
List<Predicate> conditions = new ArrayList<>();
conditions.add(cb.equal(entityRoot.get("relatedEntity").get("id"), 2));
conditions.add(cb.or(cb.isNull(entity1Entity2Join.get("columnName")), cb.equal(entity1Entity2Join.get("columnName"), true)));
query.where(conditions.toArray(new Predicate[]{})).distinct(true);
//Subquery
Subquery<Object> subQuery = cb.createQuery().subquery(Object.class);
subQuery.where(query.getRestriction()); // I want to apply the criteria query restrictions here but Hibernate is throwing exception of invalid path.
任何想法都将不胜感激。
【问题讨论】:
标签: java hibernate jpa jpa-2.0 criteria-api