Skip to content

Commit 058c56d

Browse files
committed
polish the jdoc for @onDelete and OnDeleteAction
1 parent dbef5b3 commit 058c56d

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@
7878
* deleted in the persistence context, and are not automatically
7979
* evicted from the second-level cache.
8080
* </ul>
81+
* <p>
82+
* Other options such as {@link OnDeleteAction#SET_NULL} and
83+
* {@link OnDeleteAction#SET_DEFAULT} are much less commonly used.
84+
* Note that {@code @OnDelete(SET_DEFAULT)} should be used together
85+
* with {@link ColumnDefault @ColumnDefault}.
86+
* <pre>
87+
* &#064;ManyToOne
88+
* &#064;OnDelete(action = OnDeleteAction.SET_DEFAULT)
89+
* &#064;ColumnDefault("-1")
90+
* Parent parent;
91+
* </pre>
8192
*
8293
* @author Emmanuel Bernard
8394
*/

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,33 @@ public enum OnDeleteAction {
2727

2828
/**
2929
* Cascade deletion of the parent to the child.
30+
* <p>
31+
* Produces a foreign key constraint with {@code on delete cascade}.
3032
*/
3133
CASCADE,
3234

3335
/**
3436
* Prevents deletion of the parent by raising an error immediately.
37+
* <p>
38+
* Produces a foreign key constraint with {@code on delete restrict}.
3539
*
3640
* @since 6.2
3741
*/
3842
RESTRICT,
3943

4044
/**
4145
* Set the referencing foreign key to null.
46+
* <p>
47+
* Produces a foreign key constraint with {@code on delete set null}.
4248
*
4349
* @since 6.2
4450
*/
4551
SET_NULL,
4652

4753
/**
4854
* Set the referencing foreign key to its default value.
55+
* <p>
56+
* Produces a foreign key constraint with {@code on delete set default}.
4957
*
5058
* @since 6.2
5159
*/

hibernate-core/src/test/java/org/hibernate/orm/test/ondelete/toone/ToOneOnDeleteSetNullTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import org.hibernate.annotations.ColumnDefault;
1111
import org.hibernate.annotations.OnDelete;
1212
import org.hibernate.annotations.OnDeleteAction;
13-
import org.hibernate.dialect.SybaseDialect;
13+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
1414
import org.hibernate.testing.orm.junit.DomainModel;
15+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1516
import org.hibernate.testing.orm.junit.SessionFactory;
1617
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17-
import org.hibernate.testing.orm.junit.SkipForDialect;
1818
import org.junit.jupiter.api.AfterEach;
1919
import org.junit.jupiter.api.Test;
2020

@@ -38,11 +38,7 @@ public void tearDown(SessionFactoryScope scope) {
3838
}
3939

4040
@Test
41-
@SkipForDialect(
42-
dialectClass = SybaseDialect.class,
43-
matchSubTypes = true,
44-
reason = "Sybase does not support on delete actions"
45-
)
41+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsCascadeDeleteCheck.class)
4642
public void testManyToOne(SessionFactoryScope scope) {
4743
scope.inTransaction(
4844
session -> {

hibernate-core/src/test/java/org/hibernate/orm/test/ondelete/toone/ToOneOnDeleteTest.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
import jakarta.persistence.Entity;
88
import jakarta.persistence.Id;
99
import jakarta.persistence.ManyToOne;
10-
1110
import org.hibernate.annotations.OnDelete;
1211
import org.hibernate.annotations.OnDeleteAction;
13-
import org.hibernate.dialect.SybaseDialect;
14-
15-
import org.hibernate.community.dialect.TiDBDialect;
12+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
1613
import org.hibernate.testing.orm.junit.DomainModel;
14+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1715
import org.hibernate.testing.orm.junit.SessionFactory;
1816
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19-
import org.hibernate.testing.orm.junit.SkipForDialect;
2017
import org.junit.jupiter.api.AfterEach;
2118
import org.junit.jupiter.api.Test;
2219

@@ -43,12 +40,7 @@ public void tearDown(SessionFactoryScope scope) {
4340
}
4441

4542
@Test
46-
@SkipForDialect(
47-
dialectClass = SybaseDialect.class,
48-
matchSubTypes = true,
49-
reason = "Sybase does not support on delete actions"
50-
)
51-
@SkipForDialect(dialectClass = TiDBDialect.class)
43+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsCascadeDeleteCheck.class)
5244
public void testManyToOne(SessionFactoryScope scope) {
5345
scope.inTransaction(
5446
session -> {

0 commit comments

Comments
 (0)