criteria api count query get“验证条件时出错”

qltillow  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(263)

我将向我的工作条件api实现添加一个计数查询,

CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Account> query = criteriaBuilder.createQuery(Account.class);
//THIS IS I'm going to add
CriteriaQuery<Long> cqCount = criteriaBuilder.createQuery(Long.class);
Root<Account> accountRoot = query.from(Account.class);
/**
bunch of predicate code

**/

//The original code with Predicate List
query.where(pre);

//THIS IS I'm going to add
cqCount.select(criteriaBuilder.count(accountRoot));
cqCount.where(pre);
TypedQuery<Long> typedQueryCount = entityManager.createQuery(cqCount);
Long count = typedQueryCount.getSingleResult();
//above is the added code

//the original code
TypedQuery<Account> typedQuery = entityManager.createQuery(query);
typedQuery.setMaxResults(accountFilterInfoDto.getCount());
List<Account> resultList = typedQuery.getResultList();

不管我得到什么
已解决[java.lang.illegalargumentexception:验证条件时出错]
有什么问题吗?删除添加的计数代码可以正常工作。
谢谢您。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题