hirondelle.web4j.database
Class ForeignKeyException
Object
Throwable
Exception
hirondelle.web4j.model.AppException
hirondelle.web4j.database.DAOException
hirondelle.web4j.database.ForeignKeyException
- All Implemented Interfaces:
- MessageList, Serializable
public final class ForeignKeyException
- extends DAOException
Thrown when a violation of a foreign key constraint occurs in the datastore
during an ADD, CHANGE, or DELETE operation.
This type of exception is singled out since it is so common. It allows
Action
s to catch this specific kind of exception.
For relational databases, this exception should be thrown for INSERT,
UPDATE, or DELETE operation which may violate a foreign key constraint.
Db
, DbTx
, and TxTemplate
will throw a ForeignKeyException
exception for SQLException
s having an error code matching the
ErrorCodeForForeignKey setting configured in web.xml.
See web.xml for more information.
Typical Use Case
Here, an Action
is calling a DAO method which may throw
a ForeignKeyException:
private void deleteSomething throws DAOException {
//this try..catch is needed only if the operation
//can have a foreign key problem
try {
dao.deleteSomething();
}
catch (ForeignKeyException ex){
addError("Cannot delete. Referenced by some other item.");
}
}
Here is the DAO operation which may have a foreign key constraint problem.
//It is highly recommended, but optional, to declare
//ForeignKeyException in this method header, to bring
//it to the attention of the caller
public deleteSomething() throws DAOException, ForeignKeyException {
//...elided
}
- See Also:
- Serialized Form
ForeignKeyException
public ForeignKeyException(String aMessage,
Throwable aRootCause)
- Constructor.
Arguments are passed to DAOException.DAOException(String, Throwable)
.
Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.