[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-513) Multiple class validators of the same annotationtype

John Gilbert (JIRA) noreply at atlassian.com
Wed Feb 7 18:41:40 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-513?page=comments#action_26021 ] 

John Gilbert commented on ANN-513:
----------------------------------

I have the same problem but the GenericValidator seems very verbos. Here is an example of something I am playing with:

@Expressions( 
	{ @Expression(value = "value.field1 ne value.field2", message = "Field1 must not equal Field2."),
	  @Expression(value = "value.field3 > value.field4", message = "Field3 must be greater than Field4.")
	 })
public class Entity {
	private String field1;
	private String field2;
	private Integer field3;
	private Integer field4;
	...
}    

Ignore the fact that I am using expression language.

The Expressions annotation is not linked to a ValidatorClass, but the Expression annotation is.

public @interface Expressions {
	Expression[] value();
}

@ValidatorClass(ExpressionValidator.class)
public @interface Expression {

	String value();
	String message() default "";
}

In ClassValidator when it initializes it gets all the annotations off of the class and members and checks if they have a ValidatorClass. It could also use reflection to see if the annotations aggregate other annotations which in turn are linked to a ValidatorClass.

This would require a moderate bit of rework to ClassValidator, but would make using it much cleaner.

Thoughts?

> Multiple class validators of the same annotationtype
> ----------------------------------------------------
>
>          Key: ANN-513
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-513
>      Project: Hibernate Annotations
>         Type: Improvement

>   Components: validator
>     Versions: 3.2.1
>     Reporter: Edwin van der Elst
>     Priority: Minor
>  Attachments: validators_patch.txt
>
>
> I have a suggestion for the following problem:
> I created an Validator to check if a 'date'> 'another date'
> The annotation looks like this:
> @After(property="endDate", after="beginDate", message="End should be after begin")
> Since it involves 2 properties, it is a class-level validation.
> Now....
> I want multiple 'after' validations on a single bean.
> But that is not possible (you can only place an annotation once on a class).
> My proposal is to add an annotation 'Validations':
> @Validations( {@After(...), @After(..)} )
> I could do the multiple validations in a single validatorclass, but I want all the messages added to the invalidValues array, not a single message.
> This change would also require changes in the ClassValidator class.
> What do you think of this proposal? Should I add it to Jira (I can propably implement it if there are no objections to the required changes)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list