Quote:
1. I have i.e. addDate and modDate. I want to validate against addDate <= modDate. I know I have to write my own annotation but what about null?
I should check against null in isValid() or annotate it with @notNull (what is corect/good way)?
- isValid(gets refernce for one field) so I have to create new class i.e. Dates(addDate, modDate) and custom annotation for Dates, andagain, I should annotate add/modDate @notNull?
First regarding the null check, the correct way is to return true (which says that your constraint is valid) if one of your values is null and annotate your fields with the @NotNull annotation (for example in all HV constraint validator, null value is always considered as valid). To validate your two fields, you have to create your own class level annotation[1]. By doing this, you will be able to access these fields in your validator. If you want you can also use the HV built-in constraint named @ScriptAssert[2].
[1]
http://docs.jboss.org/hibernate/validator/4.2/reference/en-US/html_single/#d0e332[2]
http://musingsofaprogrammingaddict.blogspot.com/2009/08/script-annotation-for-bean-validation.html (which is now included in the HV built-in constraints :)
Quote:
What about unique. Writing @Unique and check in isValid() what is in db tables is good or very bad idea?
This questions is generaly about "selecting" db in validators.
Look at this post
http://community.jboss.org/wiki/AccessingTheHibernateSessionWithinAConstraintValidator. The problems which might occur are discussed here.
Hope this help.
--Kevin