File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Why is my validation.xml ignored by Hibernate Validator? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Why is my validation.xml ignored by Hibernate Validator?" Watch "Why is my validation.xml ignored by Hibernate Validator?" New topic
Author

Why is my validation.xml ignored by Hibernate Validator?

Mohammad Hossein Fasihi
Greenhorn

Joined: Feb 07, 2013
Posts: 2
Hi.
I have the following validation.xml and validation-constraints.xml (for mapping) files:

validation.xml:


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
Greenhorn

Joined: Feb 07, 2013
Posts: 2
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is my validation.xml ignored by Hibernate Validator?