I've just written one of my first HQL-queries. It should look for such objects of Activity class (which contains list of objects of TodayEffort class) whose last item in todayEfforts-list has non-zero value of effort field.
Code:
SELECT DISTINCT a FROM Activity a JOIN a.todayEfforts tes WHERE ... AND (SELECT tes.effort FROM tes WHERE tes.id=(SELECT max(tes.id) FROM tes))>0
But really it finds all objects of Activity class if last item in TODAY_EFFORT table has non-zero value of effort field, and doesn't find any objects otherwise.
Please help me to fix it