简单JPA 2标准查询“;其中;条件
我正在学习jpa hibernate的基础知识 我有此查询用于获取所有用户:简单JPA 2标准查询“;其中;条件,jpa,jpa-2.0,criteria,Jpa,Jpa 2.0,Criteria,我正在学习jpa hibernate的基础知识 我有此查询用于获取所有用户: CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(); cq.select(cq.from(Utente.class)); return getEntityManager().createQuery(cq).getResultLis
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery();
cq.select(cq.from(Utente.class));
return getEntityManager().createQuery(cq).getResultList();
现在我想通过一个名为“ghost”的布尔字段进行过滤,其中它等于true(或者false,这取决于它)
翻译成:
从ghost=0的用户中选择*
我必须使用cq.where()吗?如何使用?是的,您必须使用
cq.where()
试着这样做:
Root<Utente> utente = cq.from(Utente.class);
boolean myCondition = true; // or false
Predicate predicate = cb.equal(utente.get(Utente_.ghost), myCondition);
cq.where(predicate);
Predicate predicate = cb.equal(utente.get("ghost"), myCondition);