10.9. Orphaned Keys

Unless you apply database foreign key constraints extensively, it is possible to end up with orphaned keys in your database. For example, suppose Person p has a reference to Address a. If you delete a without nulling p's reference, p's database record will wind up with an orphaned key to the non-existant a record.


One way of avoiding orphaned keys is to use dependent fields. See Section, “dependent”.

Kodo's kodo.OrphanedKeyAction configuration property controls what action to take when Kodo encounters an orphaned key. You can set this plugin string (see Section 2.4, “Plugin Configuration”) to a custom implementation of the kodo.event.OrphanedKeyAction interface, or use one of the built-in options:

Example 10.7. Custom Logging Orphaned Keys

kodo.OrphanedKeyAction: log(Channel=Orphans, Level=DEBUG)