Skip to content

Commit 5266c1c

Browse files
committed
mention all the ways @onDelete(CASCADE) can be used in the javadoc
1 parent 6a97178 commit 5266c1c

File tree

1 file changed

+35
-6
lines changed
  • hibernate-core/src/main/java/org/hibernate/annotations

1 file changed

+35
-6
lines changed

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,44 @@
2020
* @OnDelete(action = CASCADE)
2121
* Parent parent;
2222
* </pre>
23-
* Note that this results in an {@code on delete cascade} clause in
24-
* the DDL definition of the foreign key. It's completely different
25-
* to {@link jakarta.persistence.CascadeType#REMOVE}.
23+
* This annotation results in an {@code on delete cascade} clause in
24+
* the DDL definition of the foreign key.
2625
* <p>
27-
* In fact, {@code @OnDelete} may be combined with {@code cascade=REMOVE}.
26+
* The {@code @OnDelete} annotation may be applied to any field or
27+
* property representing an association or collection, or to a subclass
28+
* in a {@linkplain jakarta.persistence.InheritanceType#JOINED joined}
29+
* inheritance hierarchy.
2830
* <pre>
29-
* &#064;ManyToOne(cascade = REMOVE)
31+
* &#064;Entity
32+
* &#064;Inheritance(strategy = JOINED)
33+
* class Publication {
34+
* &#064;Id
35+
* long id;
36+
* ...
37+
* &#064;ElementCollection
38+
* &#064;OnDelete(action = CASCADE)
39+
* String&lt;String&gt; keywords;
40+
* }
41+
*
42+
* &#064;Entity
3043
* &#064;OnDelete(action = CASCADE)
31-
* Parent parent;
44+
* class Book extends Publication {
45+
* &#064;Column(unique = true);
46+
* String isbn;
47+
* ...
48+
* &#064;ManyToMany
49+
* &#064;OnDelete(action = CASCADE)
50+
* Set&lt;Author&gt; authors;
51+
* }
52+
* </pre>
53+
* <p>
54+
* The affect of {@code @OnDelete(action = CASCADE)} is quite different
55+
* to {@link jakarta.persistence.CascadeType#REMOVE}. In fact,
56+
* {@code @OnDelete} may be combined with {@code cascade=REMOVE}.
57+
* <pre>
58+
* &#064;OneToMany(mappedBy = Child_.parent, cascade = {PERSIST, REMOVE})
59+
* &#064;OnDelete(action = CASCADE)
60+
* Set&lt;Child&gt; children = new HashSet<>();
3261
* </pre>
3362
* <ul>
3463
* <li>If {@code @OnDelete(action = CASCADE)} is used in conjunction

0 commit comments

Comments
 (0)