@Override
public List<HistoricoConta> getHistoricosConta(Date dataInicial, Date dataFinal, Conta conta) {
CriteriaBuilder criteriaBuilder =
entityManager.getCriteriaBuilder();
CriteriaQuery<HistoricoConta> criteriaQuery =
criteriaBuilder.createQuery(HistoricoConta.class);
Root<HistoricoConta> root =
criteriaQuery.from(HistoricoConta.class);
criteriaQuery.select(root)
.where(
criteriaBuilder.and(
criteriaBuilder.between(root.get("dataTransacao").as(Date.class), dataInicial, dataFinal),
criteriaBuilder.equal(root.get("conta"),conta)
)
).orderBy(
criteriaBuilder.asc(root.get("dataTransacao").as(Date.class))
);
return entityManager
.createQuery(criteriaQuery)
.getResultList();