typedQuery.resultList()中的零项

时间:2016-05-06 07:27:47

标签: java jpa jpql criteria-api

我需要从日期范围内的数据库项目中获取("已创建")。查询是正确的(我在HeidiSQL中检查它)并从DB中选择正确的行,但是typedQuery.resultList()总是有0项。

CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();

CriteriaQuery<CurrencyConvertionRate> criteriaQuery = criteriaBuilder.createQuery(CurrencyConvertionRate.class);

Root<CurrencyConvertionRate> root = criteriaQuery.from(CurrencyConvertionRate.class);

List<Predicate> criteria = new ArrayList<Predicate>();

<Timestamp>get(created)={}", criteriaBuilder.greaterThanOrEqualTo(root.<Timestamp>get("created"), dateFrom).toString());
log.debug("criteriaBuilder.lessThanOrEqualTo(root.<Timestamp>get(created), dateTo={}", criteriaBuilder.lessThanOrEqualTo(root.<Timestamp>get("created"), dateTo).toString());
log.debug("root.get(currencyCode).in(currencyList)={}", root.get("currencyCode").in(currencyList).toString());

criteria.add(criteriaBuilder.greaterThanOrEqualTo(root.<Timestamp>get("created"), dateFrom));
criteria.add(criteriaBuilder.lessThanOrEqualTo(root.<Timestamp>get("created"), dateTo));
criteria.add(root.get("currencyCode").in(currencyList));
CriteriaQuery<CurrencyConvertionRate> select = criteriaQuery.select(root);
select.where(criteriaBuilder.and(criteria.toArray(new Predicate[0])));

TypedQuery<CurrencyConvertionRate> typedQuery = entityManager.createQuery(select);
return typedQuery.getResultList();

0 个答案:

没有答案