【发布时间】:2020-12-10 10:41:04
【问题描述】:
我有一个由休眠条件 api 生成的查询,它需要很长时间才能执行:
select count (entity.id)
from table
where field1 in ('...') and field2 in ('...') and ...
我已将 entity.id 替换为 '*':
select count (*)
from table
where field1 in ('...') and field2 in ('...') and ...
由于某些原因,现在它运行良好,但我无法通过条件 api 生成此查询。我正在像这样创建 Root:
Root<MyEntity> root cq.from(MyEntity.class);
有什么方法可以用 select count(*) 而不是 count(id) 生成 sql 查询?
【问题讨论】:
-
这能回答你的问题吗? JPA 2.0: count for arbitrary CriteriaQuery?
标签: hibernate jpa hibernate-criteria criteria-api