How do I write a MAX query with a where clause in JPA 2.0?

前端 未结 2 1051
心在旅途
心在旅途 2020-12-15 19:48

I\'m using JPA 2.0. Hibernate 4.1.0.Final, and Java 6. How do I write a JPA query from the following psuedo-SQL?

select max(e.dateProcessed) from Event e wh         


        
2条回答
  •  忘掉有多难
    2020-12-15 19:52

    With JPQL and CriteriaBuilder

    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq= getEntityManager().getCriteriaBuilder().createQuery();
    Root c = cq.from(getEntityClass());
    cq.select(cb.max(c.get("id")));
    

提交回复
热议问题