4.11. SQL Statement Ordering & Foreign Keys

Kodo JDO can be configured to order SQL updates to meet foreign key constraints through the boolean kodo.jdbc.ForeignKeyConstraints configuration property.

SQL statement ordering to match foreign key constraints is disabled by default. If you use foreign keys in your schema, we recommend configuring your database to use deferred foreign keys whenever possible. Deferred constraints are not evaluated until the end of the transaction, giving you greater freedom in how you design your constraints and better performance than Kodo JDO's in-memory statement ordering. If your database does not support deferred constraints, however, Kodo JDO's automatic statement ordering will make sure all dependencies are met, including circular dependencies. The example below shows how to enable statement ordering in your configuration properties file.

Example 4.14. Enabling SQL Statement Ordering

kodo.jdbc.ForeignKeyConstraints: true

If you are using Kodo to create your schema, you should consult Section, “jdbc-delete-action” for information on how to tell Kodo to create foreign key constraints at schema generation time.


You cannot use non-deferred foreign key constraints with the dynamic schema factory. Please make sure you are using one of the other factories covered in Section 8.1.2, “Schema Factory”.