-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Validating Floats/Doubles, validation constraints vs @Column
PostPosted: Fri Feb 10, 2006 2:12 pm 
Beginner
Beginner

Joined: Wed Feb 08, 2006 5:45 pm
Posts: 23
Location: Phoenix, AZ
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 10:31 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hum,
acutally the contraints works on Number but the boundaries have to be of type int currently.
Open a JIRA issue if it's still an issue for you.

Validator is the way do go: it can be tested at the java level (through the validator framework) but also apply the constraints at the DB level the same way @Column(...) does. So @notNull does at least @column(nullable=false)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 1:39 pm 
Beginner
Beginner

Joined: Wed Feb 08, 2006 5:45 pm
Posts: 23
Location: Phoenix, AZ
Issue opened: ANN-249.

Thanks for the response,
Ben


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 10:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
My question was, do you really need to set decimal boundaries? Integer is not enough?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 2:07 pm 
Beginner
Beginner

Joined: Wed Feb 08, 2006 5:45 pm
Posts: 23
Location: Phoenix, AZ
Well, I'm working with a legacy database and all of the commission percentages (I have to multiply an amount by a percentage for commissions) are in 2 scale, 2 precision format (.xx) where 0 would work on the lower bound but 1 is too high on the upper bound. So, for this case, and any other were the range is 0 <= x < 1, an Integer is not enough.

-B

_________________
Please rate me if you found my post useful.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.