select
processInstanceInfo.processInstanceId
from
ProcessInstanceInfo processInstanceInfo join processInstanceInfo.eventTypes eventTypes
where
eventTypes = :type
select
key.processInstanceId
from
CorrelationKeyInfo key
left join key.properties props
where
cast(:elem_count as integer) =
(select count(id) from CorrelationPropertyInfo cpi where cpi.correlationKey.id = key.id) and
props.value in :properties
group by key.id,key.processInstanceId
having count(key.id) = :elem_count
select
key
from
CorrelationKeyInfo key
where
key.processInstanceId = :pId