In my spring app, I have two tables. Among workers, there are bosses and both roles can make items. I want to know how many items were made by definite bosses workers (include bosses items) and made after 11.9.10 (as an example, it should be variable in method.) So the method should be
public Long fingCountByDateAndWorker(Worker worker, Instant date)
here boss worker and date of creatin item
I got the right value by the script in PostgreSQL, but I can't make the right code by Criteria API (Java) This is the script :
select distinct COUNT(item.id) FROM worker w1
JOIN worker w2 ON w1.id = w2.boss_id
JOIN item it ON it.date_create >= '2020-01-10 15:51:33'
and (it.worker_id = w2.id or it.worker_id = 2(boss worker id))
where w1.id = 2(boss worker id)
How to convert it into java criteria API code?
You have to specify the id of the parent entity. Please try with the below method