|
20 | 20 | * @OnDelete(action = CASCADE) |
21 | 21 | * Parent parent; |
22 | 22 | * </pre> |
23 | | - * Note that this results in an {@code on delete cascade} clause in |
24 | | - * the DDL definition of the foreign key. It's completely different |
25 | | - * to {@link jakarta.persistence.CascadeType#REMOVE}. |
| 23 | + * This annotation results in an {@code on delete cascade} clause in |
| 24 | + * the DDL definition of the foreign key. |
26 | 25 | * <p> |
27 | | - * In fact, {@code @OnDelete} may be combined with {@code cascade=REMOVE}. |
| 26 | + * The {@code @OnDelete} annotation may be applied to any field or |
| 27 | + * property representing an association or collection, or to a subclass |
| 28 | + * in a {@linkplain jakarta.persistence.InheritanceType#JOINED joined} |
| 29 | + * inheritance hierarchy. |
28 | 30 | * <pre> |
29 | | - * @ManyToOne(cascade = REMOVE) |
| 31 | + * @Entity |
| 32 | + * @Inheritance(strategy = JOINED) |
| 33 | + * class Publication { |
| 34 | + * @Id |
| 35 | + * long id; |
| 36 | + * ... |
| 37 | + * @ElementCollection |
| 38 | + * @OnDelete(action = CASCADE) |
| 39 | + * String<String> keywords; |
| 40 | + * } |
| 41 | + * |
| 42 | + * @Entity |
30 | 43 | * @OnDelete(action = CASCADE) |
31 | | - * Parent parent; |
| 44 | + * class Book extends Publication { |
| 45 | + * @Column(unique = true); |
| 46 | + * String isbn; |
| 47 | + * ... |
| 48 | + * @ManyToMany |
| 49 | + * @OnDelete(action = CASCADE) |
| 50 | + * Set<Author> authors; |
| 51 | + * } |
| 52 | + * </pre> |
| 53 | + * <p> |
| 54 | + * The affect of {@code @OnDelete(action = CASCADE)} is quite different |
| 55 | + * to {@link jakarta.persistence.CascadeType#REMOVE}. In fact, |
| 56 | + * {@code @OnDelete} may be combined with {@code cascade=REMOVE}. |
| 57 | + * <pre> |
| 58 | + * @OneToMany(mappedBy = Child_.parent, cascade = {PERSIST, REMOVE}) |
| 59 | + * @OnDelete(action = CASCADE) |
| 60 | + * Set<Child> children = new HashSet<>(); |
32 | 61 | * </pre> |
33 | 62 | * <ul> |
34 | 63 | * <li>If {@code @OnDelete(action = CASCADE)} is used in conjunction |
|
0 commit comments