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