-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hibernate ORM User Guide #3
Comments
6.3.13. GroupBy and Having CriteriaQuery<Tuple> q = cb.createTupleQuery(); Root<Customer> customer = q.from(Customer.class);
q.groupBy(customer.get(Customer_.status)); q.having(cb.in(customer.get(Customer_.status)).value(1).value(2)); q.select(cb.tuple(
customer.get(Customer_.status), cb.avg(customer.get(Customer_.filledOrderCount)), cb.count(customer))); This query is equivalent to the following Jakarta Persistence query language query: SELECT c.status, AVG(c.filledOrderCount), COUNT(c) FROM Customer c
GROUP BY c.status HAVING c.status IN (1, 2) |
6.3.13. GroupBy and Having
The groupBy method of the CriteriaQuery interface is used to define a partitioning of the query results into groups. The having method of the CriteriaQuery interface can be used to filter over the groups.
The arguments to the groupBy method are Expression instances.
When the groupBy method is used, each selection item that is not the result of applying an aggregate method must correspond to a path expression that is used for defining the grouping. Requirements on the types that correspond to the elements of the grouping and having constructs and their relationship to the select items are as specified in Section 4.8.
Example:
CriteriaQuery<Tuple> q = cb.createTupleQuery(); Root<Customer> customer = q.from(Customer.class);
q.groupBy(customer.get(Customer_.status)); q.having(cb.in(customer.get(Customer_.status)).value(1).value(2)); q.select(cb.tuple(
customer.get(Customer_.status), cb.avg(customer.get(Customer_.filledOrderCount)), cb.count(customer)));
This query is equivalent to the following Jakarta Persistence query language query:
SELECT c.status, AVG(c.filledOrderCount), COUNT(c) FROM Customer c
GROUP BY c.status HAVING c.status IN (1, 2) ` |
Pro Jpa2 : ebook firstCheck! :1:
Note
Criteria API
Code block :
Examples
Example 562. Hibernate getResultStream() with an entity result type
https://docs.jboss.org/hibernate/stable/orm/userguide/html_single/Hibernate_User_Guide.html#:~:text=public%20class%20PersonWrapper,createQuery(criteria).getResultList()%3B
The text was updated successfully, but these errors were encountered: