我尝试使用 JPA 计算行数。我想使用 where 子句但是我不能。
CriteriaBuilder qb = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> cq = qb.createQuery(Long.class);
cq.select(qb.count(cq.from(MyEntity.class)));
cq.where(); //how to write where clause
return entityManager.createQuery(cq).getSingleResult();
我如何设置 where 子句,例如 where age=“45”。提前致谢。
原文由 Harun ERGUL 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用
ParameterExpression
。注意: _未经测试_。参考。