[hibernate-dev] [Validator] Method level validation and cross parameter validator

Hardy Ferentschik hibernate at ferentschik.de
Fri Feb 18 07:00:42 EST 2011

On Fri, 18 Feb 2011 09:01:16 +0100, Emmanuel Bernard  
<emmanuel at hibernate.org> wrote:

> Reading the Google design by contract work, I realized that we do not  
> cover cross-parameter validation in method-level validation.

I assume you are talking about cofoja (http://code.google.com/p/cofoja),  

> //We want to make sure departure is after arrival.
> void book(Date arrival, Date departure);
> Any idea on ow best to address that?

Some ideas:

Introduce an equivalent to class level validators:

  void book(Date arrival, Date departure);

@MyMethodValidator could contain a marker annotation so that we know that  
have a method level validation. At first thought we would have to pass  
object arrays
to the validator implementations. This is of course at odds with the type  
safety approach
of BV.
Also if the method has a return value it is not directly clear by reading  
the code
whether the return value would be validated or the parameters.

An alternative would be something similar to @ScriptAssert:

  void book(Date arrival, Date departure);

Gunnar already thought about naming parameters using @Named (HV-409),  
maybe we could also do
something like:

  void book(@Named("arrival") Date arrival, @Named("departure") Date  


More information about the hibernate-dev mailing list