Hi,
My program has a pair of entity classes which represent a parent-child relationship (avoiding circular references). It also needs to support orphaned children. The entity classes are as follows (pseudocode)
Child.java:
Code:
@Entity
public class Child {
//... property/method definitions and bean accessors
}
Parent.java:
Code:
@Entity
public class Parent {
@ManyToMany
private Set<Child> children;
//... other property/method definitions and bean accessors
}
My DAO uses the following HQL query to get the orphaned children:
Code:
SELECT child FROM Child AS child WHERE child NOT IN (SELECT DISTINCT child FROM Parent AS parent INNER JOIN parent.children AS child)
The HQL query works exactly as I want it to. My question is, is there a way to do the same thing using the Criteria API?