Skip to content
Merged
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 @@ -11,9 +11,17 @@

/**
* A {@link JDBCException} indicating that the requested DML operation
* resulted in violation of a defined integrity constraint.
* resulted in violation of a defined data integrity constraint.
*
* @author Steve Ebersole
*
* @see jakarta.persistence.Column#unique
* @see jakarta.persistence.Column#nullable
* @see jakarta.persistence.Column#check
* @see jakarta.persistence.JoinColumn#foreignKey
* @see jakarta.persistence.Table#uniqueConstraints
* @see jakarta.persistence.Table#check
* @see jakarta.persistence.JoinTable#foreignKey
*/
public class ConstraintViolationException extends JDBCException {

Expand Down Expand Up @@ -43,37 +51,62 @@ public ConstraintViolationException(String message, SQLException root, String sq
/**
* Returns the name of the violated constraint, if known.
*
* @return The name of the violated constraint, or null if not known.
* @apiNote Some databases do not reliably report the name of
* the constraint which was violated. Furthermore,
* many constraints have system-generated names.
*
* @return The name of the violated constraint, or {@code null}
* if the name is not known.
*
* @see jakarta.persistence.ForeignKey#name
* @see jakarta.persistence.UniqueConstraint#name
* @see jakarta.persistence.CheckConstraint#name
*/
public @Nullable String getConstraintName() {
return constraintName;
}

/**
* Returns the kind of constraint that was violated.
* Returns the {@linkplain ConstraintKind kind} of constraint
* that was violated.
*/
public ConstraintKind getKind() {
return kind;
}

/**
* Enumerates the kinds of constraint violation recognized by Hibernate.
* Enumerates the kinds of integrity constraint violation recognized
* by Hibernate.
*/
public enum ConstraintKind {
/**
* A {@code not null} constraint violation.
*
* @apiNote The {@linkplain #getConstraintName constraint name}
* in this case is usually just the column name.
*
* @see jakarta.persistence.Column#nullable
*/
NOT_NULL,
/**
* A {@code unique} or {@code primary key} constraint violation.
*
* @see jakarta.persistence.Column#unique
* @see jakarta.persistence.Table#uniqueConstraints
*/
UNIQUE,
/**
* A {@code foreign key} constraint violation.
*
* @see jakarta.persistence.JoinColumn#foreignKey
* @see jakarta.persistence.JoinTable#foreignKey
*/
FOREIGN_KEY,
/**
* A {@code check} constraint violation.
*
* @see jakarta.persistence.Column#check
* @see jakarta.persistence.Table#check
*/
CHECK,
/**
Expand Down