如何动态创建CriteriaQuery

时间:2011-04-19 00:59:55

标签: jpa-2.0 criteriaquery

我想为此查询创建等效的CriteriaQuery: 从用户u中选择u,其中u.name =“John”,u.surname =“Black”,u.middlename =“Small”; 但我对“where”谓词有疑问。 感谢

1 个答案:

答案 0 :(得分:0)

您可以使用:


CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery c = ...;
Root root = ...;

Predications name = builder.equal(root.get("name"), name);
Predications surname = ...;
Predications middlename = ...;

c.where(name, surname, middlename);