Auto-Maintained Back Pointers


joist-domain automatically maintains both sides of foreign key relationships.

This means if you add a child to a parent, you don’t have to worry about explicitly setting the parent on the child, for fear that later the child will call getParent() and get back null. joist maintains both sides.


Using parent.addChild(c) means c.getParent() will just work:

    Parent p = new Parent();
    Child c = new Child();
    assertTrue(c.getParent() == p); // passes

And using child.setParent(p) means that p.getChilds() will just work:

    Parent p = new Parent();
    Child c = new Child();
    assertTrue(p.getChilds().contains(c)); // passes

Lazy Loading

Note that when calling child.setParent(parent), and the implicit parent.addChild(child) is done by joist-domain for you, the parent’s “other” children are not pulled back from the database.

The changes to the parent.childs collection are kept lazy until the parent.getChilds() method is explicitly called. Then the database is hit and any parent.childs added/removed items that had been kept lazy are applied to the results before being returned from parent.getChilds().