[英]Hibernate Criteria Subquery Restrictions
我有一個條件查詢和一個子查詢,我想將條件查詢的限制應用於子查詢。 以下是我迄今為止嘗試過的。
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.
任何想法將不勝感激。
您收到該錯誤並且操作正確是正常的,最后您試圖在子查詢的 where 中建立一些您尚未定義任何內容的新查詢的條件,要解決它嘗試更改此行
Subquery <Object> subQuery = cb.createQuery().subquery(Object.class);
為了這
Subquery <Object> subQuery = query.subquery(Object.class);
從您已經創建的查詢創建子查詢,而不是由此創建新查詢和子查詢
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.