I changed the query to:
SELECT distinct demand FROM MyDemand demand
where exists ( SELECT 'x' FROM MyDemand invd
JOIN invd.MyDemandLine line
JOIN line.Restr restr
where restr.Order=:order
and invd=demand)