我試圖通過另一個查詢的結果來縮小Hibernate Criteria查詢的結果集。我知道如何解決這個問題與JPQL:通過子查詢縮小查詢結果
FROM DocPackage p WHERE
EXISTS (SELECT g
FROM ObjectGroup g JOIN g.items i, Person per
WHERE g=p.applicantGroup
AND i.objectClass = 'org.cp.model.common.Person'
AND i.objectId=per.id
AND lower(concat(per.firstName,' ',per.lastName)) like :applicant
)
但我無法想象如何使用標準進行此類查詢。任何想法如何使用Criteria實現這個選擇?使用Hibernate 3.3。
UPD:試圖解決這個問題,我已經做了如下條件查詢:
Criteria resultCriteriaQuery = this.hibernateSession.createCriteria(DocPackage.class, "pack");
DetachedCriteria personSubquery = DetachedCriteria.forClass(Person.class, "pers").
add(Restrictions.like("pers.loFstLstName", "%" + searchObject.getApplicant().toLowerCase() + "%")).
add(Restrictions.eqProperty("itm.objectId", "pers.id"));
DetachedCriteria applicantsSubquery = DetachedCriteria.forClass(ObjectGroup.class, "objGrp").
add(Restrictions.eqProperty("pack.applcantGroup", "objGrp")).
createAlias("objGrp.items", "itm").
add(Restrictions.eq("itm.objectClass", "org.cp.model.common.Person")).
add(Subqueries.exists(personSubquery));
resultCriteriaQuery.add(Subqueries.exists(applicantsSubquery));
但它不工作。我在resultCriteriaQuery.list()
上有NullPointerException
。這個查詢有什麼問題?有任何想法嗎?