views:

54

answers:

2

Hi ,

My project have two main requirements

1) Different set of rules applied to same object at insertion and while updating it.

2) Different validation rules based on locale.

In ADDRESS object STATE field requires different validation rules For USA: STATE cannot be NULL. For everywhere else it can be NULL.

For first requirement i am already using GROUPS. Is there a way to achieve second requirements.

I am using: Hibernate Validator 4.0.1 GA Hibernate 5.2.6

A: 

I would make the country (Locale based or not is up to you) part of the Address and use a custom class-level constraint to do the validation.

Pascal Thivent
Thanks Pascal. But isn't there any kind of support in the framework for localized validations. Like different validation xml files for each region ( mechanism similar to language properties files i.e messages.properties , messages_fr.properties etc ). Or anything like multiple group options ( a group with in a group or something of this sort ).
asim99
A: 

This question got answered on the Hibernate Validator forum. Best way to go is a class-level constraint or a Validator instance per Locale. I really wouldn't recommend the latter, but it's a possibility.

Hardy