java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
st.orm.PersistenceException
st.orm.IntegrityViolationException
- All Implemented Interfaces:
Serializable
Thrown when a value breaks a rule of its table: a write the database refuses for a constraint, a null in a
non-nullable field at write time, or a value that
validateOrThrow finds too large for its column.
The database refuses a write for one constraint at a time, so a violation it reports comes alone;
validateOrThrow reports every violation of the entity at once. Each IntegrityViolation names the
kind of rule and the fields it resolves to, so a caller matches on a metamodel key:
try {
users.insert(user);
} catch (IntegrityViolationException e) {
if (e.violations(User_.email).stream().anyMatch(v -> v instanceof IntegrityViolation.Unique)) {
// The email is taken.
}
throw e;
}
A violation the database reported passes through the template's exception mapper like any failure the database reported, with the driver's exception as its cause, so a mapper translates it to its own type.
- Since:
- 1.16
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionIntegrityViolationException(String message, List<IntegrityViolation> violations) Constructs a new exception with the specified detail message and violations.IntegrityViolationException(String message, List<IntegrityViolation> violations, @Nullable Throwable cause) Constructs a new exception with the specified detail message, violations and cause. -
Method Summary
Modifier and TypeMethodDescriptionReturns the violations.violations(Metamodel<?, ?> field) Returns the violations that resolve to the given field.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
IntegrityViolationException
Constructs a new exception with the specified detail message and violations.- Parameters:
message- the detail message.violations- the violations, at least one.
-
IntegrityViolationException
public IntegrityViolationException(String message, List<IntegrityViolation> violations, @Nullable Throwable cause) Constructs a new exception with the specified detail message, violations and cause.- Parameters:
message- the detail message.violations- the violations, at least one.cause- the failure the database reported, ornullwhen Storm found the violations itself.
-
-
Method Details
-
violations
Returns the violations. A violation the database reported comes alone;validateOrThrowreports every violation of the entity.- Returns:
- the violations, at least one.
-
violations
Returns the violations that resolve to the given field.- Parameters:
field- the field, as a metamodel key.- Returns:
- the violations on the field; empty when none resolves to it.
-