ALBERLAU blog

Blog about my personal experience in software development.

Friday, March 20, 2009

 

AnnotationsBasedValidator for JPA entities in SpringFramework

Despite there is Hibernate Validator, I wrote my own. It is adopted to use with SpringFramework WEB MVC framework. Why I not used Hibernate Validator? In Hibernate we have @NotNull, @Length annotations and in @Column we have simmilar annotations. I think that violates DRY principle. Result of Hibernate Validator is array of InvalidValue. For Spring it is better to have messages in ResultBinding.

Usage example:




protected IAnnotationsBasedValidator annotationsBasedValidator;

@Autowired
public void setAnnotationsBasedValidator(IAnnotationsBasedValidator annotationsBasedValidator) {
this.annotationsBasedValidator = annotationsBasedValidator;
}




then somewhere in your code:




annotationsBasedValidator.validate(payment, bindingResult);




As a result bindingResult is filled with validation messages(if there is violated constraints for annotations).

This validator fully utilizes JPA @Column length, nullable, precission, scale, @JoinColumn nullable, @OneToOne , @Embedded. Nested objects for @JoinColumn , @OneToOne , @Embedded is also validated traversing full object tree, except those who is not !propertyInitializationInfo.isInitializaed(cs) (lazy properties).

Additionally it supports annotations: RegexChecker, RangeChecker, BooleanResultChecker to call static method to validate value.

Validator source
Comments:
I appreciate remarkable advertisment! I must say i valued checking the item, tonsil stone you could be an awesome creator.For certain i will make sure you save your items your web site Satellite direct and definately will frequently come home down the road. I must promote anyone carry on an individual's amazing articles, enjoy a pleasant holiday penis advantage saturday!
 
Post a Comment

Subscribe to Post Comments [Atom]





<< Home

Archives

January 2008   February 2008   March 2009  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]