Skip to content

Commit 84ab8be

Browse files
committed
HHH-18936 javadoc for cascade REMOVE with @onDelete(CASCADE)
1 parent 9ca0019 commit 84ab8be

File tree

1 file changed

+23
-0
lines changed
  • hibernate-core/src/main/java/org/hibernate/annotations

1 file changed

+23
-0
lines changed

hibernate-core/src/main/java/org/hibernate/annotations/OnDelete.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,33 @@
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+
* &#064;ManyToOne
20+
* &#064;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+
* &#064;ManyToOne(cascade = REMOVE)
30+
* &#064;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
*

0 commit comments

Comments
 (0)