Two errors (see attachments):
Error #1.
select f from Food f where f.id = (select fn.foodId from FoodName fn where (fn.name = :name or lower(fn.name) like :nameLowercase) group by fn.foodId) and (f.user.id is null or f.user.id = :userId or f.id = (select f2.id from Food f2, User u where f2.user.id = u.id and u.class = 'Sponsor'))
The above query is a valid one !
IDEA handles the query correctly when I replace '=' with 'in' (see attachment), but I don't want to use 'in' because MySQL performance declines when 'in' is used instead of '=' !
Error #2.
select f from Food f where f.id = (select fn.foodId from FoodName fn where (fn.name = :name or lower(fn.name) like :nameLowercase) group by fn.foodId) and (f.user.id is null or f.user.id = :userId or f.id = (select f2.id from Food f2, User u where f2.user.id = u.id and u.class = 'Sponsor'))
Looks like IDEA don't like x.class !