I search for not referenced child objects of a many-to-one association mapping with a query like this:
Code:
select c
from Parent p
right join p.child c
where p is null
It expands to SQL similar to this and works fine:
Code:
select * from parent p
right outer join child c on p.child_id=c.id
where p.id is null
Problems arise when using inheritance.
See the following query where Parent2 is mapped as a subclass of Parent (one table per class hierarchy) with a new introduced child2-property.
Code:
select c2
from Parent2 p2
right join p2.child2 c2
where p2 is null
It never returns any result as it expands to SQL like this:
Code:
select * from parent p
right outer join child c on p.child_id=c.id
where p.type in ('P2') // test discriminator for Parent2 subclass
and p.id is null
The discriminator test prevents the query from selecting results. Is there another way to find unreferenced c2 objects? I can't use a bidirectional reference because the child table is proprietary and can't be altered.
best regards
Apex