[hibernate-dev] Exception model

Emmanuel Bernard emmanuel at hibernate.org
Wed Feb 18 04:45:50 EST 2009


I spent a long time scrutinizing the spec for exception cases. This  
email list exceptional cases and propose to associate specific  
exceptions to them or not. Please review and tell me:
  - if you think I forgot cases that needs additional consideration.
  - which model you favor (see B)


A. EXCEPTION CASES

I described the error cases and a fine grained Exception model (see B)  
and have a few questions see ???

1. Error report

Use for other frameworks to report violation reports

**
  * Report the result of constraint violations
  *
  * @author Emmanuel Bernard
  */
public class ConstraintViolationException extends ValidationException {
	private final Set<ConstraintViolation> constraintViolations;

	/**
	 * Creates a constraint violation report
	 *
	 * @param message error message
	 * @param constraintViolations Set of ConstraintViolation
	 */
	public ConstraintViolationException(String message,  
Set<ConstraintViolation> constraintViolations) {
		super( message );
		this.constraintViolations = constraintViolations;
	}

	/**
	 * Creates a constraint violation report
	 *
	 * @param constraintViolations Set of ConstraintViolation
	 */
	public ConstraintViolationException(Set<ConstraintViolation>  
constraintViolations) {
		super();
		this.constraintViolations = constraintViolations;
	}

	/**
	 * Set of constraint violations reported during a validation
	 *
	 * @return Set of CosntraintViolation
	 */
	public Set<ConstraintViolation> getConstraintViolations() {
		return constraintViolations;
	}
}

2. Execution exceptions

ie during validator.validate(...);


Constraint Declaration
These can be found a compilation time with an annotation processor or  
an IDE
???    UnsupportedTypeException or should it be  
AmbiguousConstraintUsageException
         More than one ConstraintValidator targeting the same type
         declared property type property has too many matches
     UnsupportedTypeException
         declared property type property has no match
     ConstraintDefinitionException
         composition parameter overriding (name, composing constraint  
or incompatible parameter types)
         constraint composed of itself


Constraint implementation
     ConstraintInitializationException
???        initialize() must raise a RTE will be wrapped OR should we  
not wrap
     UnsupportedTypeException
          isValid incompatible type (detected by impl) => same as  
"declared property type property has no match"
     ConstraintExcecutionException
          isValid throws a RTE will be wrapped into  
ConstraintValidatorExecutionException
     ConstraintCreationException
          ConstraintValidatorFactory fails with RTE. Wraps it.

???  should we collapse that into a ConstraintExecutionException or  
even ValidationException

Groups
       Can be checked at built time by an IDE or an AnnotationProcessor
       GroupDefinitionException
            cyclic dependency between groups sequences and group  
inheritance
            missing group X on a Default group overriding
            Group sequence name used in a constraint declaration
            group is not an interface

Various
     IllegalArgumentException
          if object to validate is null, or empty set?
???    Calls to SPi like MessageInterpolator / TraversableResolver  
should be wrapped?


3. Bootstrap

ProviderNotFoundException
     cannot find matching provider
     cannot find any provider

ConfigurationException
   cannot read XML cong
   more than one XML conf
   no no-arg constructor on classes described by XML

MappingException
   cannot read XML mapping
   entity described more than once
   field/getter described more than once
   Wrong class / field  / getter name
   Wrong constraint declaration
   Wrong constraint definition


B. EXCEPTION MODEL

We have three approaches:

1. specialize an exception when the application can do something about  
it
In this case all exceptions are ValidationException except  
ConstraintViolationException

2. specialize exceptions to provide informations to the user
ValidationException (root)
ConstraintViolationException
AmbiguousConstraintUsageException
UnsupportedTypeException
ConstraintDefinitionException
ConstraintInitializationException
ConstraintExcecutionException
ConstraintCreationException
GroupDefinitionException
ProviderNotFoundException
ConfigurationException
MappingException

3. a man in the middle approach with some exception collapsing

ValidationException (root)
ConstraintViolationException
ConstraintDeclarationException (instead of UnsupportedTypeException  
and AmbiguousConstraintUsageException)
ConstraintDefinitionException
ConstraintExcecutionException
GroupDefinitionException
ConfigurationException




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-dev/attachments/20090218/48cf943e/attachment.html 


More information about the hibernate-dev mailing list