File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
hibernate-core/src/main/java/org/hibernate/annotations Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 15
15
/**
16
16
* Specifies an {@code on delete} action for a foreign key constraint.
17
17
* The most common usage is {@code @OnDelete(action = CASCADE)}.
18
+ * <pre>
19
+ * @ManyToOne
20
+ * @OnDelete(action = CASCADE)
21
+ * Parent parent;
22
+ * </pre>
18
23
* Note that this results in an {@code on delete cascade} clause in
19
24
* the DDL definition of the foreign key. It's completely different
20
25
* to {@link jakarta.persistence.CascadeType#REMOVE}.
21
26
* <p>
27
+ * In fact, {@code @OnDelete} may be combined with {@code cascade=REMOVE}.
28
+ * <pre>
29
+ * @ManyToOne(cascade = REMOVE)
30
+ * @OnDelete(action = CASCADE)
31
+ * Parent parent;
32
+ * </pre>
33
+ * <ul>
34
+ * <li>If {@code @OnDelete(action = CASCADE)} is used in conjunction
35
+ * with {@code cascade=REMOVE}, then associated entities are fetched
36
+ * from the database, marked deleted in the persistence context,
37
+ * and evicted from the second-level cache.
38
+ * <li>If {@code @OnDelete(action = CASCADE)} is used on its own,
39
+ * <em>without</em> {@code cascade=REMOVE}, then associated
40
+ * entities are not fetched from the database, are not marked
41
+ * deleted in the persistence context, and are not automatically
42
+ * evicted from the second-level cache.
43
+ * </ul>
44
+ * <p>
22
45
* Like database triggers, {@code on delete} actions can cause state
23
46
* held in memory to lose synchronization with the database.
24
47
*
You can’t perform that action at this time.
0 commit comments