Hi-
I am trying to use the Hibernate Validator to annotate a Float property (a price) but @Range, @Min, and @Max don't seem to support it. When I try adding an 'f' to the end of the number (9999.99f) or cast it ( (float)9999.99 ) I get an type mismatch error saying 'cannot convert a float to an int' (for @Min, @Max) or '... a long' (for @Range). I also tried using a Double instead of a Float and I get the same errors. The Annotations 3.1b8 reference stats that @Min, @Max, and @Range can be applied on a "property (numeric or string representation of a numeric)." What I'd like to know is, is there another way of validating a float (or should I be using the @Min( value=0.00f ), @Max( value=9999.99f ), @Range( min=0.00f, max=9999.99f ) constraints differently)? I know that I can use the @Column to specify a scale and precision of a property, but can I use a validation? If not, are there any plans to support it in the future?
This also brings up another question I have, what is the better practice - using validation constraints or using @Column to constrain the values of a property. In other words, @NotNull or @Column( nullable=false )? From what I've seen in the reference documentation and a couple posts on this forum it seems like the validation constraints are the way to go. Can anyone provide an example (or explaination) of why one would want to use one over the other in a given situation?
Thanks for any help on the subject,
Ben
|