jakartaee / jakartaee/persistence
support for ON DELETE CASCADE
- Dominant language
- Java
- Stars
- 268
- Forks
- 78
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 13
Description
Both Hibernate and (I believe) EclipseLink have at least some sort of support for using `on delete cascade` to remove child entities when a parent entity is `remove()`d.
This is of course much more efficient than executing (potentially multiple) `DELETE` statements, with the downside that we can't promise that lifecycle callbacks get processed. But this isn't the only scenario where we skip lifecycle callbacks, and anyway this would be an opt-in thing.
So this is a candidate for standardization.
I guess the _simplest_ API for this would be to add a `onDelete` member to the `ForeignKey` annotation. The downside of this approach is it's a bit ugly:
```java
@ManyToOne
@JoinColumn(foreignKey=@ForeignKey(onDelete=CASCADE))
public Parent parent;
```
It also feels a bit unnatural to me to put this on the `@ManyToOne` side of the association instead of on the `@OneToMany` side where you would put `cascade=REMOVE`.
But I guess this is bearable.
[Hibernate has something slightly more natural, an `@OnDelete` annotation which may be specified at either end of the association, but it does feel like this rightly belongs in `@ForeignKey`.]
Contributor guide
Research direction
Start with the existing ForeignKey annotation and review how Hibernate and EclipseLink support ON DELETE CASCADE. The issue does not name files or tests; completion would require an agreed standard API, documented lifecycle-callback behavior, and corresponding implementation and tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100