[hibernate-issues] [Hibernate-JIRA] Updated: (HV-135) Constraints can contains constraint annotations to validate params before initialize is called
Hardy Ferentschik (JIRA)
noreply at atlassian.com
Fri Mar 16 12:47:48 EDT 2012
[ https://hibernate.onjira.com/browse/HV-135?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Hardy Ferentschik updated HV-135:
---------------------------------
Fix Version/s: (was: 4.3.0.Final)
> Constraints can contains constraint annotations to validate params before initialize is called
> ----------------------------------------------------------------------------------------------
>
> Key: HV-135
> URL: https://hibernate.onjira.com/browse/HV-135
> Project: Hibernate Validator
> Issue Type: New Feature
> Components: engine
> Reporter: Emmanuel Bernard
>
> not high priority
> From Sebastian Thomschke
> --------------------------------------
> I just had a look through the Hibernate Validator code, what struck me
> was the way how you validate parameters. E.g.
> private void validateParameters() {
> if ( min < 0 ) {
> throw new ValidationException( "The min parameter cannot be
> negative." );
> }
> if ( max < 0 ) {
> throw new ValidationException( "The max paramter cannot be
> negative." );
> }
> if ( max < min ) {
> throw new ValidationException( "The length cannot be
> negative." );
> }
> }
> I just had the idea, why don't we use the constraint annotations for the
> built-in constraints themselves? E.g.
> /**
> * @return size the element must be higher or equal to
> */
> @Min(0)
> int min() default 0;
> /**
> * @return size the element must be lower or equal to
> */
> @Min(0)
> int max() default Integer.MAX_VALUE;
> Then this kind of parameter validation could be done by the framework
> and must not be repeated in every validator implementation.
> What do you think?
> Regards,
> Seb
> --------------------------------------
> Emmanuel
> Your idea is interesting. It could lead to infinite recursion if someone does not pay attention but could work.
> I think it would better be a product feature though instead of a spec feature for this rev at least. We can't have "class" level constraints though as it conflicts with the composition model.
> WDYT?
> it seems to me that the ValidationException is wrong in the example you gave.
> http://opensource.atlassian.com/projects/hibernate/browse/HV-134
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list