Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/DesignDocs/324341

< EclipseLink‎ | DesignDocs
Revision as of 15:39, 2 September 2010 by James.sutherland.oracle.com (Talk | contribs) (New page: <div style="margin:5px;float:right;border:1px solid #000000;padding:5px">__TOC__</div> = Design Specification: On Delete Cascade = [http://bugs.eclipse.org/324341 ER 324341] [[Talk:Eclip...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Design Specification: On Delete Cascade

ER 324341

Feedback

Document History

Date Author Version Description & Notes
2010-09-02 James 0.1 Draft

Project overview

Allow delete cascading to be defined and handled by the database.


Concepts

ON DELETE CASCADE is a database foreign key constraint option that automatically removes the dependent rows.


Requirements

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.

Design Constraints

Must be database independent.

Functionality

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.


Testing

Add CascadeOnDelete to some DDL generation model classes. Add CascadeOnDelete to fieldaccess model classes and add deletion tests.

API

  • ClassDescriptor.setIsCascadeOnDeleteSetOnDatabaseOnSecondaryTables()
  • ForeignReferenceMapping.setIsCascadeOnDeleteSetOnDatabase()
  • @CascadeOnDelete

Config files

  • orm.xml
<entity cascadeOnDelete="true">
<one-to-one cascadeOnDelete="true">
<one-to-many cascadeOnDelete="true">
<many-to-many cascadeOnDelete="true">

Documentation

Should be documented under extended annotations, and schema generation. Also needs to be linked under cascade remove and remove orphans.

Open Issues

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?

Decisions

Issue # Description / Notes Decision

Future Considerations

  • Other constraint options such as ON DELETE NULL.

Back to the top