这样一个巨大的退步怎么可能是合理的!?!我错过了什么吗?实体经理版本的可读性非常糟糕。
session()。createCriteria(Entity.class).add(Restrictions.eq(“id”),id).uniqueResult();
与
EntityManager em = getEntityManager();
try {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Transaction> cq = cb.createQuery(Transaction.class);
Metamodel m = em.getMetamodel();
EntityType<Transaction> Transaction_ = m.entity(Transaction.class);
Root<Transaction> transaction = cq.from(Transaction.class);
// Error here. cannot find symbol. symbol: variable creationDate
cq.where(cb.between(transaction.get(Transaction_.creationDate), startDate, endDate));
// I also tried this:
// cq.where(cb.between(Transaction_.getDeclaredSingularAttribute("creationDate"), startDate, endDate));
List<Transaction> result = em.createQuery(cq).getResultList();
return result;
} finally {
em.close();
}