3

我正在使用 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))

我在这里发现了类似的东西。但并不满足。

4

0 回答 0