[hibernate-dev] Hibernate Validator: bean-level validation

Robert Spielmann spielmann at codecentric.de
Thu Dec 6 10:47:00 EST 2007


Hi all,

I ran into some sort of problem while trying to use Hibernate Validator for context-based attribute validation. A property of the bean only had to be present under certain circumstances. I found two possible ways to deal with this:

1. Validate the aforementioned property using something other than Hibernate Validator because annotation parameters must be constant at compile time and cannot be set at runtime,
2. Write my own bean-level validator in order to get access to the entire bean, which brings in a problem with the InvalidValue array: for bean-level annotations, the returned property name is null. As soon as you have more than one bean-level annotation, you cannot distinguish between the fields the annotation(s) tried to validate.

It would be very nice if I could:

a) Pass parameters to the validator at runtime or
b) return a not-null property name for bean-level validation.

Hope that I haven't missed a way which solves this problem; I'd like very much to hear about your opinions on this.

Mit freundlichen Grüßen / Best regards

Robert Spielmann
IT Consultant

-- 

codecentric GmbH
Grünewalder Str. 29-31
42657 Solingen

Telefon +49 (212) 2494-322
Fax +49 (212) 2494-334
Mobil +49 (151) 14705709

E-Mail spielmann at codecentric.de

Internet www.codecentric.de <http://www.codecentric.de/> 

Geschäftsführer: Peter Gierse, Mirko Novakovic und Rainer Vehns
Sitz der Gesellschaft: Solingen

Registergericht: Amtsgericht Wuppertal, HRB 19214





More information about the hibernate-dev mailing list