Code: Select all
cb.size(student.get(Student_.presentations)
Moderator: admin
Code: Select all
cb.size(student.get(Student_.presentations)
What is the use of zero presentation? First option will provide same result, without zero presentations, correct?You need a left outer join between Student and Presentation because you want to include even those departments that have no presentation. Their count should be 0. If you use INNER join (which is the default when you don't specify a JoinType), you will only those depts which have a presentation.
Hi,2. group by s.dept implies:
q.groupBy(student.get(Student_.enrollment).get(Enrollment_.dept));
Note that customer.join("enrollment") is same as customer.join(Student_.enrollment).
3. Since we are selecting individual fields (dept and count) as opposed to a complete entity object, we need to select a tuple:
q.select(cb.tuple(student.get("enrollment").get("dept"), cb.count(student) )), which is same as
q.multiselect(student.get(Student_.enrollment).get(Enrollment_.dept), cb.count(presentations) )
Code: Select all
count(student)
Code: Select all
count(presentations)
Hi
Code: Select all
cq.multiselect(empRoot.get(Employee_.enrollment).get(Enrollment_.department), cb.count(empRoot));
==> generated SQL:
select e.department, count(e.id)
from Employee e left outer join Presentation p
on e.id=p.presenter_id
group by e.department
==> results
department=MATHS, count=3
department=ENGLISH, count=1
Code: Select all
cq.multiselect(empRoot.get(Employee_.enrollment).get(Enrollment_.department), cb.count(presentations));
==> generated SQL:
select e.department, count(p.presentationTitle)
from Employee e left outer join Presentation p
on e.id=p.presenter_id
group by e.department
==> results
department=MATHS, count=3
department=ENGLISH, count=0
Except for the fact that you need an outer join, why is option 2 wrong? I thought that a path expression (get) can create an implicit join?cb.count(student.get(Student_.presentations) will not work until you join the Student table with Presentation table.
Users browsing this forum: No registered users and 8 guests