<div dir="ltr">My bad, I mixed the validation.xml and constraints.xml files (and mixed the XSDs). This is what I done and it works (with version 1.1 everywhere) :<div><br></div><div><br></div><div style><b>validation.xml</b></div>
<div style><div><font face="courier new, monospace"><?xml version="1.0" encoding="UTF-8"?></font></div><div><font face="courier new, monospace"><validation-config</font></div><div><font face="courier new, monospace"> xmlns="<a href="http://jboss.org/xml/ns/javax/validation/configuration">http://jboss.org/xml/ns/javax/validation/configuration</a>"</font></div>
<div><font face="courier new, monospace"> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"</font></div><div><font face="courier new, monospace"> xsi:schemaLocation="<a href="http://jboss.org/xml/ns/javax/validation/configuration">http://jboss.org/xml/ns/javax/validation/configuration</a> validation-configuration-1.1.xsd"</font></div>
<div><font face="courier new, monospace"> version="1.1"></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> <constraint-mapping>META-INF/constraints.xml</constraint-mapping></font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"></validation-config></font></div><div><br></div><div style><b>constraints.xml</b></div><div style><div><font face="courier new, monospace"><?xml version="1.0" encoding="UTF-8"?></font></div>
<div><font face="courier new, monospace"><constraint-mappings</font></div><div><font face="courier new, monospace"> xmlns="<a href="http://jboss.org/xml/ns/javax/validation/mapping">http://jboss.org/xml/ns/javax/validation/mapping</a>"</font></div>
<div><font face="courier new, monospace"> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"</font></div><div><font face="courier new, monospace"> xsi:schemaLocation="<a href="http://jboss.org/xml/ns/javax/validation/mapping">http://jboss.org/xml/ns/javax/validation/mapping</a> validation-mapping-1.1.xsd"</font></div>
<div><font face="courier new, monospace"> version="1.1"></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> <bean class="org.agoncal.book.javaee7.chapter03.ex14.Book14" ignore-annotations="false"></font></div>
<div><font face="courier new, monospace"> <field name="title"></font></div><div><font face="courier new, monospace"> <constraint annotation="javax.validation.constraints.NotNull"/></font></div>
<div><font face="courier new, monospace"> </field></font></div><div><font face="courier new, monospace"> <field name="price"></font></div><div><font face="courier new, monospace"> <constraint annotation="javax.validation.constraints.NotNull"/></font></div>
<div><font face="courier new, monospace"> <constraint annotation="javax.validation.constraints.Min"></font></div><div><font face="courier new, monospace"> <element name="value">2</element></font></div>
<div><font face="courier new, monospace"> </constraint></font></div><div><font face="courier new, monospace"> </field></font></div><div><font face="courier new, monospace"> <field name="description"></font></div>
<div><font face="courier new, monospace"> <constraint annotation="javax.validation.constraints.Size"></font></div><div><font face="courier new, monospace"> <element name="max">2000</element></font></div>
<div><font face="courier new, monospace"> </constraint></font></div><div><font face="courier new, monospace"> </field></font></div><div><font face="courier new, monospace"> </bean></font></div><div>
<font face="courier new, monospace"></constraint-mappings></font></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/1/2 Emmanuel Bernard <span dir="ltr"><<a href="mailto:emmanuel@hibernate.org" target="_blank">emmanuel@hibernate.org</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It looks like you forgot a space in your xsi:schemaLocation<br>
<br>
xsi:schemaLocation="<a href="http://jboss.org/xml/ns/javax/validation/mappingvalidation-mapping-1.1.xsd" target="_blank">http://jboss.org/xml/ns/javax/validation/mappingvalidation-mapping-1.1.xsd</a>"<br>
-><br>
xsi:schemaLocation="<a href="http://jboss.org/xml/ns/javax/validation/mapping" target="_blank">http://jboss.org/xml/ns/javax/validation/mapping</a> validation-mapping-1.0.xsd"<br>
<br>
But that raises an interesting question. Today we have added a version<br>
number in validation.xml and I believe the behavior is well defined.<br>
What about mapping files? I don't think we considered that yet. What<br>
should we do. Throwing a few ideas:<br>
<br>
- add a version number like we did for validation.xml<br>
- enforce consistent version use between validation.xml and the<br>
contained mapping files<br>
<br>
Thoughts?<br>
<br>
Emmanuel<br>
<div><div class="h5"><br>
On Wed 2013-01-02 16:38, Antonio Goncalves wrote:<br>
> Hi all,<br>
><br>
> I'm trying to use validation.xml 1.1 to add constraints to me beans but I<br>
> get a ValidationException. Here is the validation.xml file :<br>
><br>
> <?xml version="1.0" encoding="UTF-8"?><br>
> <constraint-mappings<br>
> xmlns="<a href="http://jboss.org/xml/ns/javax/validation/mapping" target="_blank">http://jboss.org/xml/ns/javax/validation/mapping</a>"<br>
> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>"<br>
> xsi:schemaLocation="<a href="http://jboss.org/xml/ns/javax/validation/mappingvalidation-mapping-1.1.xsd" target="_blank">http://jboss.org/xml/ns/javax/validation/mappingvalidation-mapping-1.1.xsd</a>"<br>
> version="1.1"><br>
><br>
> <default-package>org.agoncal.book.javaee7.chapter03</default-package><br>
> <bean class="ex14.Book" ignore-annotations="false"><br>
> <field name="title"><br>
> <constraint annotation="javax.validation.constraints.NotNull"/><br>
> </field><br>
> <field name="price"><br>
> <constraint annotation="javax.validation.constraints.NotNull"/><br>
> <constraint annotation="javax.validation.constraints.Min"><br>
> <element name="min">2</element><br>
> </constraint><br>
> </field><br>
> </bean><br>
> </constraint-mappings><br>
><br>
> In the spec (§8.1.4. XML Schema) it mentions something about versions, so<br>
> I've tried to change my schema to 1.0 but still get my exception. Here is<br>
> the part of the spec that talks about version issues and the stack trace.<br>
><br>
> Any idea ?<br>
> Thanks<br>
><br>
><br>
><br>
> --------------------------------------------<br>
> Stacktrace<br>
> 8.1.4. XML Schema<br>
><br>
> This section contains the XML schema used for constraint mapping<br>
> descriptors.<br>
><br>
> >From Bean Validation revision 1.1 onwards, mapping authors must specify the<br>
> used version of the schema within the version attribute of the<br>
> constraint-mappings element. Implementations supporting Bean Validation 1.1<br>
> must properly parse mapping descriptors of Bean Validation 1.0 and 1.1. If<br>
> the version attribute attribute is not given, schema version 1.0 is to be<br>
> assumed by the Bean Validation Provider.<br>
><br>
> In case an unknown version is given (e.g. if a mapping descriptor adhering<br>
> to a future schema version is parsed by a Bean Validation 1.1 provider) a<br>
> ValidationException is raised.<br>
><br>
><br>
><br>
> --------------------------------------------<br>
> Stacktrace<br>
><br>
><br>
><br>
> javax.validation.ValidationException: HV000100: Unable to parse<br>
> META-INF/validation.xml.<br>
> at<br>
> org.hibernate.validator.internal.xml.ValidationXmlParser.unmarshal(ValidationXmlParser.java:121)<br>
> at<br>
> org.hibernate.validator.internal.xml.ValidationXmlParser.parseValidationXml(ValidationXmlParser.java:77)<br>
> at<br>
> org.hibernate.validator.internal.engine.ConfigurationImpl.getBootstrapConfiguration(ConfigurationImpl.java:263)<br>
> at<br>
> org.hibernate.validator.internal.engine.ConfigurationImpl.parseValidationXml(ConfigurationImpl.java:328)<br>
> at<br>
> org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:195)<br>
> at<br>
> javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:107)<br>
> at<br>
> org.agoncal.book.javaee7.chapter03.ex14.Book14Test.init(Book14Test.java:36)<br>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
> at<br>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)<br>
> at<br>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br>
> at<br>
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)<br>
> at<br>
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)<br>
> at<br>
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)<br>
> at<br>
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)<br>
> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)<br>
> at org.junit.runner.JUnitCore.run(JUnitCore.java:160)<br>
> at<br>
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)<br>
> at<br>
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)<br>
> at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)<br>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
> at<br>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)<br>
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)<br>
> Caused by: javax.xml.bind.UnmarshalException<br>
> - with linked exception:<br>
> [org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 22; cvc-elt.1<br>
> : Déclaration de l'élément 'constraint-mappings' introuvable.]<br>
> at<br>
> javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:335)<br>
> at<br>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:512)<br>
> at<br>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:209)<br>
> at<br>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:181)<br>
> at<br>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:235)<br>
> at<br>
> org.hibernate.validator.internal.xml.ValidationXmlParser.unmarshal(ValidationXmlParser.java:117)<br>
> ... 24 more<br>
> Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 22;<br>
> cvc-elt.1 : Déclaration de l'élément 'constraint-mappings' introuvable.<br>
> at<br>
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)<br>
> at<br>
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1901)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:741)<br>
> at<br>
> com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:565)<br>
> at<br>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:86)<br>
> at<br>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:135)<br>
> at<br>
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:376)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:602)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3065)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:881)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)<br>
> at<br>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)<br>
> at<br>
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)<br>
> at<br>
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)<br>
> at<br>
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)<br>
> at<br>
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)<br>
> at<br>
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)<br>
> at<br>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203)<br>
> ... 27 more<br>
><br>
> janv. 02, 2013 4:23:09 PM org.hibernate.validator.internal.util.Version<br>
> <clinit><br>
> INFO: HV000001: Hibernate Validator 5.0.0.Alpha2<br>
> janv. 02, 2013 4:23:09 PM<br>
> org.hibernate.validator.internal.xml.ValidationXmlParser unmarshal<br>
> INFO: HV000007: META-INF/validation.xml found. Parsing XML based<br>
> configuration.<br>
><br>
> --<br>
> Antonio Goncalves<br>
> Software architect and Java Champion<br>
><br>
</div></div>> Web site <<a href="http://www.antoniogoncalves.org/" target="_blank">http://www.antoniogoncalves.org/</a>> |<br>
> Twitter<<a href="http://twitter.com/agoncal" target="_blank">http://twitter.com/agoncal</a>><br>
> | LinkedIn <<a href="http://www.linkedin.com/in/agoncal" target="_blank">http://www.linkedin.com/in/agoncal</a>> | Paris<br>
> JUG<<a href="http://www.parisjug.org/" target="_blank">http://www.parisjug.org/</a>><br>
> | Devoxx France <<a href="http://www.devoxx.fr/" target="_blank">http://www.devoxx.fr/</a>><br>
<br>
> _______________________________________________<br>
> beanvalidation-dev mailing list<br>
> <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
<br>
_______________________________________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Antonio Goncalves <br>Software architect and Java Champion<br><br><a href="http://www.antoniogoncalves.org/" target="_blank">Web site</a> | <a href="http://twitter.com/agoncal" target="_blank">Twitter</a> | <a href="http://www.linkedin.com/in/agoncal" target="_blank">LinkedIn</a> | <a href="http://www.parisjug.org/" target="_blank">Paris JUG</a> | <a href="http://www.devoxx.fr/" target="_blank">Devoxx France</a>
</div>