I've read a lot of articles about lazy loading, but none seem to mention my specific question. Let's say my class looks like this:
Code:
public class Node {
private List<Node> children;
private Node parent;
private String name;
public List<Node> getChildren() {
return children;
}
public Node getParent() {
return parent;
}
public void setChildren(List<Node> children) {
this.children = children;
}
public void setParent(Node parent) {
this.parent = parent;
}
// ...
}
Now, if lazy loading is occurring and I call getChildren(), do ALL children below this node get loaded or only this nodes direct descendants? How do I only get the direct descendants?
Also, I keep seeing this:
If the association is nullable, Hibernate cannot lazy-load it by design.
And I've even read the explanation for why, but I still don't understand. Why can't my table be defined like this:
col1: myId
col2: myOneToOneId
...
In this case, hibernate does not have to query the one-to-one table to figure out if the one-to-one relationship exists. It can see if it exists by checking if it's OWN myOneToOneId is null. Why doesn't hibernate allow you to do this?