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 1717/**
1818 * Specifies an {@code on delete} action for a foreign key constraint.
1919 * The most common usage is {@code @OnDelete(action = CASCADE)}.
20+ * <pre>
21+ * @ManyToOne
22+ * @OnDelete(action = CASCADE)
23+ * Parent parent;
24+ * </pre>
2025 * Note that this results in an {@code on delete cascade} clause in
2126 * the DDL definition of the foreign key. It's completely different
2227 * to {@link jakarta.persistence.CascadeType#REMOVE}.
2328 * <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>
2447 * Like database triggers, {@code on delete} actions can cause state
2548 * held in memory to lose synchronization with the database.
2649 *
You can’t perform that action at this time.
0 commit comments