I have the following validation.xml and validation-constraints.xml (for mapping) files:
and validation-constraints.xml :
I have put both files in the root of my resources folder in maven project, among with other XML configurations. This will put the files in the root of classpath after compiling the project with maven. so it should be read by hibernate validator.
Same class was working with annotations. I just like the configuration to be in it's own place, so I moved it to XML.
After running the tests now the same tests that used to pass with annotations, do not pass with XML.
It's like it just ignores the XML files all together.
I create the validator in Java simply:
P.S. I have got the basic skeleton of the above XML files from the reference documentation of hibernate.
Mohammad Hossein Fasihi
Joined: Feb 07, 2013
Found the solution:
One has to put the validation.xml under the classpath under META-INF. JSR 303 states that, but the reference implementation "Hibernate Validator" has not said it in in it's reference manual.
Same problem has been reported as a question/answer here in stackoverflow.
I saw that link before I posted here but I didn't believe the guy until got a debug level log of the validator. The log says that it's looking for a "META-INF/validation.xml" !
Putting validation.xml under a new folder, named "META-INF", solved the problem.
CAUTION! This is not the same as META-INF in the root of a JAR/WAR package. You should create a new folder named META-INF in the root of the classpath, where you put your packages. See the "stackoverflow" link above.