I want to select all SystemUsers belonging to organisations, which have not downloaded a certain document.
Code:
select distinct u from SystemUser u
join u.userGroups g
where 4 in elements(g.permissions) and
not exists (
select org from Organisation org
where org in elements(u.organisations)
and org not in (
select d.downloadingOrganisations from Document d where d.id = ?
)
)
But this results in invalid SQL:
Code:
Unexpected token: . in statement ... not in (select . from document document6_ ...
How can I write the query correctly?