File tree Expand file tree Collapse file tree 4 files changed +25
-18
lines changed
main/java/org/hibernate/annotations
test/java/org/hibernate/orm/test/ondelete/toone Expand file tree Collapse file tree 4 files changed +25
-18
lines changed Original file line number Diff line number Diff line change 78
78
* deleted in the persistence context, and are not automatically
79
79
* evicted from the second-level cache.
80
80
* </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
+ * @ManyToOne
88
+ * @OnDelete(action = OnDeleteAction.SET_DEFAULT)
89
+ * @ColumnDefault("-1")
90
+ * Parent parent;
91
+ * </pre>
81
92
*
82
93
* @author Emmanuel Bernard
83
94
*/
Original file line number Diff line number Diff line change @@ -27,25 +27,33 @@ public enum OnDeleteAction {
27
27
28
28
/**
29
29
* Cascade deletion of the parent to the child.
30
+ * <p>
31
+ * Produces a foreign key constraint with {@code on delete cascade}.
30
32
*/
31
33
CASCADE ,
32
34
33
35
/**
34
36
* Prevents deletion of the parent by raising an error immediately.
37
+ * <p>
38
+ * Produces a foreign key constraint with {@code on delete restrict}.
35
39
*
36
40
* @since 6.2
37
41
*/
38
42
RESTRICT ,
39
43
40
44
/**
41
45
* Set the referencing foreign key to null.
46
+ * <p>
47
+ * Produces a foreign key constraint with {@code on delete set null}.
42
48
*
43
49
* @since 6.2
44
50
*/
45
51
SET_NULL ,
46
52
47
53
/**
48
54
* Set the referencing foreign key to its default value.
55
+ * <p>
56
+ * Produces a foreign key constraint with {@code on delete set default}.
49
57
*
50
58
* @since 6.2
51
59
*/
Original file line number Diff line number Diff line change 10
10
import org .hibernate .annotations .ColumnDefault ;
11
11
import org .hibernate .annotations .OnDelete ;
12
12
import org .hibernate .annotations .OnDeleteAction ;
13
- import org .hibernate .dialect . SybaseDialect ;
13
+ import org .hibernate .testing . orm . junit . DialectFeatureChecks ;
14
14
import org .hibernate .testing .orm .junit .DomainModel ;
15
+ import org .hibernate .testing .orm .junit .RequiresDialectFeature ;
15
16
import org .hibernate .testing .orm .junit .SessionFactory ;
16
17
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
17
- import org .hibernate .testing .orm .junit .SkipForDialect ;
18
18
import org .junit .jupiter .api .AfterEach ;
19
19
import org .junit .jupiter .api .Test ;
20
20
@@ -38,11 +38,7 @@ public void tearDown(SessionFactoryScope scope) {
38
38
}
39
39
40
40
@ 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 )
46
42
public void testManyToOne (SessionFactoryScope scope ) {
47
43
scope .inTransaction (
48
44
session -> {
Original file line number Diff line number Diff line change 7
7
import jakarta .persistence .Entity ;
8
8
import jakarta .persistence .Id ;
9
9
import jakarta .persistence .ManyToOne ;
10
-
11
10
import org .hibernate .annotations .OnDelete ;
12
11
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 ;
16
13
import org .hibernate .testing .orm .junit .DomainModel ;
14
+ import org .hibernate .testing .orm .junit .RequiresDialectFeature ;
17
15
import org .hibernate .testing .orm .junit .SessionFactory ;
18
16
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
19
- import org .hibernate .testing .orm .junit .SkipForDialect ;
20
17
import org .junit .jupiter .api .AfterEach ;
21
18
import org .junit .jupiter .api .Test ;
22
19
@@ -43,12 +40,7 @@ public void tearDown(SessionFactoryScope scope) {
43
40
}
44
41
45
42
@ 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 )
52
44
public void testManyToOne (SessionFactoryScope scope ) {
53
45
scope .inTransaction (
54
46
session -> {
You can’t perform that action at this time.
0 commit comments