Skip to content

Commit 8cb8ea8

Browse files
gavinkingdreab8
authored andcommitted
HHH-18936 javadoc for cascade REMOVE with @onDelete(CASCADE)
1 parent 046dfda commit 8cb8ea8

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
@@ -17,10 +17,33 @@
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+
* &#064;ManyToOne
22+
* &#064;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+
* &#064;ManyToOne(cascade = REMOVE)
32+
* &#064;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
*

0 commit comments

Comments
 (0)