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 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+ * @ManyToOne
88+ * @OnDelete(action = OnDeleteAction.SET_DEFAULT)
89+ * @ColumnDefault("-1")
90+ * Parent parent;
91+ * </pre>
8192 *
8293 * @author Emmanuel Bernard
8394 */
Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff line change 1010import org .hibernate .annotations .ColumnDefault ;
1111import org .hibernate .annotations .OnDelete ;
1212import org .hibernate .annotations .OnDeleteAction ;
13- import org .hibernate .dialect . SybaseDialect ;
13+ import org .hibernate .testing . orm . junit . DialectFeatureChecks ;
1414import org .hibernate .testing .orm .junit .DomainModel ;
15+ import org .hibernate .testing .orm .junit .RequiresDialectFeature ;
1516import org .hibernate .testing .orm .junit .SessionFactory ;
1617import org .hibernate .testing .orm .junit .SessionFactoryScope ;
17- import org .hibernate .testing .orm .junit .SkipForDialect ;
1818import org .junit .jupiter .api .AfterEach ;
1919import 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 -> {
Original file line number Diff line number Diff line change 77import jakarta .persistence .Entity ;
88import jakarta .persistence .Id ;
99import jakarta .persistence .ManyToOne ;
10-
1110import org .hibernate .annotations .OnDelete ;
1211import 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 ;
1613import org .hibernate .testing .orm .junit .DomainModel ;
14+ import org .hibernate .testing .orm .junit .RequiresDialectFeature ;
1715import org .hibernate .testing .orm .junit .SessionFactory ;
1816import org .hibernate .testing .orm .junit .SessionFactoryScope ;
19- import org .hibernate .testing .orm .junit .SkipForDialect ;
2017import org .junit .jupiter .api .AfterEach ;
2118import 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 -> {
You can’t perform that action at this time.
0 commit comments