Iam使用Eclipselink中的条件构建器创建动态查询。我为每个限定符创建谓词,例如。像这儿。
Predicate predicate = criteriaBuilder.like(expression, criteriaBuilder.parameter(String.class, //Any string));
如果我使用该谓词实例重新运行相同的查询,则会获取错误的行
CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
CriteriaQuery<Address> countCriteria = cb.createQuery(Address.class);
countCriteria.select(predicate);
Query query = entityManager.createQuery(criteriaQuery);
在第一轮中获取:
SELECT t1.ID, t1.ADDRESSLINE1, t1.ADDRESSLINE2, t1.PHONENUMBER, t1.cityId, t1.personId FROM PERSON t0, ADDRESS t1 WHERE (t0.LASTNAME LIKE ? AND (t0.ID = t1.personId))
在第二轮中获取:
SELECT t2.ID, t2.ADDRESSLINE1, t2.ADDRESSLINE2, t2.PHONENUMBER, t2.cityId, t2.personId FROM PERSON t0, ADDRESS t2, ADDRESS t1 WHERE (t0.LASTNAME LIKE ? AND (t0.ID = t1.personId))
我发现了类似here的东西。但不满意。