This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Validation -JSR303 and the fly likes Why is my validation.xml ignored by Hibernate Validator? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java JSRs » Validation -JSR303
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Why is my validation.xml ignored by Hibernate Validator?
 
Similar Threads
issues integrating seam2.1.1 and facelets 1.1.14 to myfaces 1.25, spring 2.5 and hibernate 3.4 app
validator exception in Struts 1
How to commit transaction on multi-databases with different schema ?
Struts validation framework
not validating