Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 316632 - CriteriaBuilder having clause is ignored
Summary: CriteriaBuilder having clause is ignored
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-11 11:44 EDT by Patrice Lachance CLA
Modified: 2022-06-09 10:06 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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