Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 316632

Summary: CriteriaBuilder having clause is ignored
Product: z_Archived Reporter: Patrice Lachance <patrice.lachance>
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: j.edward.rayl, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Patrice Lachance CLA 2010-06-11 11:44:27 EDT
Build Identifier: 

The having clause of a CriteriaQuery is ignored in this simple query. The generated JPQL/SQL query does not contain the having clause.

CriteriaQuery<Ecole> c = cb.createQuery(Ecole.class);
Root<Ecole> ec = c.from(Ecole.class);
Join<Ecole, Journee> j = ec.join("journeeCollection", JoinType.LEFT);
Expression<Number> expDateLimiteInscrMax = cb.max(j.get("dateLimiteInscription").as(Number.class));
c.having(cb.ge(expDateLimiteInscrMax, 1234567890);

The workaround is to use a multiselect query like this :

CriteriaQuery<Object[]> c = cb.createQuery(Object[].class);
Root<Ecole> ec = c.from(Ecole.class);
Join<Ecole, Journee> j = ec.join("journeeCollection", JoinType.LEFT);
Expression<Number> expDateLimiteInscrMax = cb.max(j.get("dateLimiteInscription").as(Number.class));
c.having(cb.ge(expDateLimiteInscrMax, 1234567890);
c.multiselect(ec, cb.literal(1)).groupBy(ec);

Reproducible: Always
Comment 1 Tom Ware CLA 2010-06-14 14:37:10 EDT
Changing to Enhancement.  See section 4.7 of the JPA 2.0 specification.  It indicates that support of HAVING without GROUP BY is optional and non-portable.
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:06:32 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink