Version 4.10.0

hirondelle.web4j.database
Class ForeignKeyException

Object
  extended by Throwable
      extended by Exception
          extended by hirondelle.web4j.model.AppException
              extended by hirondelle.web4j.database.DAOException
                  extended by 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 Actions 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 SQLExceptions 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

Constructor Summary
ForeignKeyException(String aMessage, Throwable aRootCause)
          Constructor.
 
Method Summary
 
Methods inherited from class hirondelle.web4j.model.AppException
add, add, add, getMessages, isEmpty, isNotEmpty, toString
 
Methods inherited from class Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ForeignKeyException

public ForeignKeyException(String aMessage,
                           Throwable aRootCause)
Constructor.

Arguments are passed to DAOException.DAOException(String, Throwable).


Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.