fadlyfayruz
New Member
I have this object that builds a tree in the database. Each node points to its parent, or is null. I need this relationship to be bi-directional, so each node also knows its children nodes. When a node is deleted IS_ACTIVE gets set to false. How do I modify these annotations such that only children with IS_ACTIVE set to true get loaded?\[code\]@Entity@Table(name = "node")public class Node { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PARENT_NODE_ID") private Node parentNode; @OneToMany(mappedBy = "parentNode", fetch = FetchType.LAZY) private Set<Node> childrenNodes; @Column(name = "IS_ACTIVE", nullable = false) private boolean isActive; //other fields that shouldn't matter left out.}\[/code\]Currently my unit tests are running in the same transaction, so I have to use session.refresh(node) to get the children nodes to load at all, but every time it loads all of the children ignoring my filters and where clause.What is the correct way to annotate this class so the children only the active children load? Does it matter if the children are lazy-loaded?*Please note I have search for answers to this.As an example, this question seems related, but the solution does not work. I belive it is different because my join is self-referencing... but it might be due to something else I am missing. annotation to filter results of a @OneToMany association