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