Skip to content

polish the jdoc for @OnDelete and OnDeleteAction #10261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@
* deleted in the persistence context, and are not automatically
* evicted from the second-level cache.
* </ul>
* <p>
* Other options such as {@link OnDeleteAction#SET_NULL} and
* {@link OnDeleteAction#SET_DEFAULT} are much less commonly used.
* Note that {@code @OnDelete(SET_DEFAULT)} should be used together
* with {@link ColumnDefault @ColumnDefault}.
* <pre>
* &#064;ManyToOne
* &#064;OnDelete(action = OnDeleteAction.SET_DEFAULT)
* &#064;ColumnDefault("-1")
* Parent parent;
* </pre>
*
* @author Emmanuel Bernard
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,33 @@ public enum OnDeleteAction {

/**
* Cascade deletion of the parent to the child.
* <p>
* Produces a foreign key constraint with {@code on delete cascade}.
*/
CASCADE,

/**
* Prevents deletion of the parent by raising an error immediately.
* <p>
* Produces a foreign key constraint with {@code on delete restrict}.
*
* @since 6.2
*/
RESTRICT,

/**
* Set the referencing foreign key to null.
* <p>
* Produces a foreign key constraint with {@code on delete set null}.
*
* @since 6.2
*/
SET_NULL,

/**
* Set the referencing foreign key to its default value.
* <p>
* Produces a foreign key constraint with {@code on delete set default}.
*
* @since 6.2
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

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

@Test
@SkipForDialect(
dialectClass = SybaseDialect.class,
matchSubTypes = true,
reason = "Sybase does not support on delete actions"
)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsCascadeDeleteCheck.class)
public void testManyToOne(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.dialect.SybaseDialect;

import org.hibernate.community.dialect.TiDBDialect;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

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

@Test
@SkipForDialect(
dialectClass = SybaseDialect.class,
matchSubTypes = true,
reason = "Sybase does not support on delete actions"
)
@SkipForDialect(dialectClass = TiDBDialect.class)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsCascadeDeleteCheck.class)
public void testManyToOne(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down