1Z0-898 · Question #18
The developer wants to write a criteria query that will return the number of orders made by customer of each county. Assume that customer is an entity with a unidirectional one-to-many relationship…
The correct answer is A. CriteriaBuilder cb> =. Incorrect: Not B, Not C: Use multiselect, not select. Not D: Use one Join, not two. Use multiselect, count and Group By.multiselect() method is used because we are going to get compound result and not one entity type. CriteriaBuilder cb = em.getCriteriaBuilder()…
Question
The developer wants to write a criteria query that will return the number of orders made by customer of each county. Assume that customer is an entity with a unidirectional one-to-many relationship to the Order entity and that Address is an embeddable class, with an attribute country of type String. Which one of the queries below correctly achieves this?
Options
- ACriteriaBuilder cb> = ...
- BCriteriaBuilder cb> = ...
- CCriteriaBuilder cb> = ...
- DCriteriaBuilder cb = ...
How the community answered
(54 responses)- A85% (46)
- B2% (1)
- C4% (2)
- D9% (5)
Explanation
Incorrect: Not B, Not C: Use multiselect, not select. Not D: Use one Join, not two. Use multiselect, count and Group By.multiselect() method is used because we are going to get compound result and not one entity type. CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Object[]> query = cb.createQuery(Object[].class); Root<Department> d = query.from(Department.class); Join<Department,Teacher> teachers = d.join("teachers"); query.multiselect(d.get("name"),cb.count(teachers)).groupBy(d.get("name"));
Topics
Community Discussion
No community discussion yet for this question.