我正在尝试通过另一个查询的结果来缩小 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 进行这样的查询。任何想法如何使用标准实施此选择?使用休眠 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));
但它不起作用。我有一个NullPointerException
。resultCriteriaQuery.list()
这个查询有什么问题?有任何想法吗?