Design Specification: On Delete Cascade
|Date||Author||Version Description & Notes|
Allow delete cascading to be defined and handled by the database.
ON DELETE CASCADE is a database foreign key constraint option that automatically removes the dependent rows.
Support specifying that a descriptor's secondary tables, or related table cascade the delete on the database. Support generating DDL to cascade deletion in auto DDL generation. Support omitting delete SQL for multiple table and joined inheritance descriptors. Support omitting delete SQL for relationships, 1-1, 1-m, m-m, dc, ac.
Must be database independent.
An @CascadeOnDelete annotation will be added. It can be set on an Entity, or relationship. On an Entity it defines that secondary or joined inheritance tables should cascade the delete on the database. On a OneToOne the related object is deleted cascaded on the database. This is only allowed for mappedBy/target-foriegn key 1-1s (because of constraint direction). On a OneToMany the related objects are deleted cascaded on the database. On a ManyToMany the join table is deleted cascaded on the database (target objects cannot be cascade even if private because of constraint direction). On a DirectCollection, direct table is deleted cascaded on the database. On a AggregateCollection, aggregate table is deleted cascaded on the database.
Auto DDL generation will set the onDeleteCascade flag on the ForeignKeyDefinition based on the mapping.
DeleteObject and DeleteAll queries will check the descriptor and only delete from the first table if cascaded.
DirectCollection, AggregateCollection and ManyToMany will avoid executing the delete SQL if cascaded.
OneToOne and OneToMany mappings will record their dependencies as having been delete on the database in the unit of work. Deletion will then check this to avoid executing the SQL. Note that the DeleteObject queries will still execute as normal, just no SQL will occur.
Add CascadeOnDelete to some DDL generation model classes. Add CascadeOnDelete to fieldaccess model classes and add deletion tests.
<entity cascadeOnDelete="true"> <one-to-one cascadeOnDelete="true"> <one-to-many cascadeOnDelete="true"> <many-to-many cascadeOnDelete="true">
Should be documented under extended annotations, and schema generation. Also needs to be linked under cascade remove and remove orphans.
|Issue #||Owner||Description / Notes|
|1||What databases support ON DELETE CASCADE, do any use a different syntax?|
|2||On lock errors will occur on delete cascades for relatinoships, should not be used with optimistic locking on 1-1, 1-m?|
|Issue #||Description / Notes||Decision|
- Other constraint options such as ON DELETE NULL.