Hi, i need to perform an exists with a subquery, but i read in a previous post
http://forum.hibernate.org/viewtopic.php?t=930043&highlight=elements+subquery
that elements only applies to collections.
The SQL query to translate is below, all my entities are mapped in hibernate as you would expect and are working fine. I use bags for all collections.
Code:
select distinct a.*
from workflow_alarm a,
core_user u,
workflow_project wproj
where (u.user_login in ('birju','kirill','discover')
or wproj.id in (1,2,3,4,5,65,6,7))
and
(
exists
(
select null
from workflow_user_alarm ua
where ua.user_id = u.id
and ua.alarm_id = a.id
)
or exists
(
select null
from workflow_user_process up,
workflow_process p
where up.user_id = u.id
and up.process_id = p.id
and p.id = a.process_id
)
or exists
(
select null
from workflow_user_project uproj,
workflow_project proj,
workflow_process proc
where u.id = uproj.user_id
and uproj.project_id = proj.id
and proj.id = proc.project_id
and a.process_id = proc.id
)
or exists
(
select null
from workflow_process proc
where proc.project_id = wproj.id
and a.process_id = proc.id
)
);
Are selects supported within exists()? Can you give me any pointers as to go about this?
Any help would be much appreciated.
Thanks,
Birju