-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Hibernate validation is failing
PostPosted: Mon Oct 08, 2012 5:36 pm 
Newbie

Joined: Tue Jul 24, 2012 2:39 pm
Posts: 10
Hi I have written the validation logic and I am testing it and it is failing for Failure scenario.

It is giving successful request, when it suppose to fail, not sure if it is validating or not.

Please find the validating xml below. Please let me know what is wrong.

<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping/validation-mapping-1.0.xsd"
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">

<default-package>com.java.json</default-package>

<bean class="GetDocumentsRequest" ignore-annotations="false" >
<field name="requestInfo" ignore-annotations="false" >
<constraint annotation="javax.validation.constraints.NotNull"/>
</field>

<field name="requestingDocumentList" ignore-annotations="false" >
<constraint annotation="javax.validation.constraints.NotNull"/>
</field>
</bean>

<!-- Inner Elements for Fields defined above -->
<bean class="RequestInfo" ignore-annotations="false" >
<field name="requestID" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
<field name="timeStamp" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
<field name="sendingNode" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
<field name="partnerName" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
</bean>

<bean class="RequestingDocumentList" ignore-annotations="false" >
<field name="programId" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
</bean>
</constraint-mappings>

Thanks.


Top
 Profile  
 
 Post subject: Re: Hibernate validation is failing
PostPosted: Tue Oct 09, 2012 4:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
No idea what you are asking here. Is this related to your question https://forum.hibernate.org/viewtopic.php?f=9&t=1024487?


Top
 Profile  
 
 Post subject: Re: Hibernate validation is failing
PostPosted: Tue Oct 09, 2012 8:52 am 
Newbie

Joined: Tue Jul 24, 2012 2:39 pm
Posts: 10
I am asking if the xml validation is right or not, because it does not validate the request at all, it is always gives success even if the request has missing fields.


Top
 Profile  
 
 Post subject: Re: Hibernate validation is failing
PostPosted: Tue Oct 09, 2012 5:13 pm 
Newbie

Joined: Tue Jul 24, 2012 2:39 pm
Posts: 10
The "RequestingDocumentList" bean is a list and it is not getting validated, even I included <valid/> in the bean, I have debugged it and found that, it is including an empty list if it does not find the data for it, even if I give the "requestingDocumentList" as empty, it is not validating (it is not failing), which has a notNull constraint for "programId".

Please let me know how to validate this.

<bean class="GetDocumentsRequest" ignore-annotations="false" >
<field name="requestInfo" ignore-annotations="false" >
<constraint annotation="javax.validation.constraints.NotNull"/>
<valid/>
</field>

<field name="requestingDocumentList" ignore-annotations="false" >
<constraint annotation="javax.validation.constraints.NotNull"/>
<valid/>
</field>
</bean>

<bean class="RequestInfo" ignore-annotations="false" >
<field name="requestID" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
<field name="timeStamp" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
<field name="sendingNode" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
<field name="partnerName" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
</bean>

<bean class="RequestingDocumentList" ignore-annotations="false" >
<field name="programId" ignore-annotations="false" >
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
</field>
</bean>

Thanks.


Top
 Profile  
 
 Post subject: Re: Hibernate validation is failing
PostPosted: Tue Oct 09, 2012 5:49 pm 
Newbie

Joined: Tue Jul 24, 2012 2:39 pm
Posts: 10
Now I am getting UnmarshalException. Please help me.


Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'valid'. One of '{"http://jboss.org/xml/ns/javax/validation/mapping":constraint}' is expected.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:314)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:505)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:206)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:179)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:232)
at org.hibernate.validator.internal.xml.XmlMappingParser.getValidationConfig(XmlMappingParser.java:620)
... 53 more
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'valid'. One of '{"http://jboss.org/xml/ns/javax/validation/mapping":constraint}' is expected.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:417)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3182)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1806)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:550)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:78)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:135)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:200)
... 56 more

Thanks.


Top
 Profile  
 
 Post subject: Re: Hibernate validation is failing
PostPosted: Tue Oct 09, 2012 10:11 pm 
Newbie

Joined: Tue Jul 24, 2012 2:39 pm
Posts: 10
Also, I want to know how can I specify the size of the string, integer and also the size of the List in the validation xml file.

Please let me know about it.

Thanks.


Top
 Profile  
 
 Post subject: Re: Hibernate validation is failing
PostPosted: Fri Nov 02, 2012 7:30 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

As it seems your XML mapping file doesn't adhere to the XML schema as defined by the Bean Validation spec (see http://beanvalidation.org/1.0/spec/#xml-mapping-xsd). In particular you have to specify the <valid/> element before any <constraint> elements within <field> and <getter>.

To specify attribute values of constraints within an XML mapping, use the <element> element like this:

Code:
<field name="seatCount">
    <constraint annotation="javax.validation.constraints.Size">
        <element name="max">20</element>
    </constraint>
</field>


You might also be interested in the chapter on XML configuration of the Hibernate reference guide (http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html/validator-xmlconfiguration.html).

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Hibernate validation is failing
PostPosted: Tue Jan 22, 2013 7:24 am 
Newbie

Joined: Tue Jan 22, 2013 7:08 am
Posts: 3
it is always gives success even if the request has missing fields.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.