-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate multiple cross-field validation of same type
PostPosted: Tue Mar 22, 2011 9:24 pm 
Newbie

Joined: Tue Mar 22, 2011 9:16 pm
Posts: 2
Hi,

I've written a custom constraint and validator to check that a date field is greater than or equal to another date field in the same class. I've implemented the inner class List on this constraint so that more than one date field can be validated.

The problem I'm having is that only one validation error will be shown at a time, even if both constraints should fail. After debugging, it appears as though only one constraint is validated, and if that fails, the other is ignored.

Is this a restriction of the bean validation spec or is there some way to ensure that both constraints are validated at class level? Multiple constraints at field level work as expected.


Top
 Profile  
 
 Post subject: Re: Hibernate multiple cross-field validation of same type
PostPosted: Wed Mar 23, 2011 5:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Could you post the code for your custom constraint, together with an example entity you are using it on?

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate multiple cross-field validation of same type
PostPosted: Wed Mar 23, 2011 6:02 am 
Contributor
Contributor

Joined: Mon Feb 28, 2011 7:27 pm
Posts: 20
Location: France
Hi,

As said Hardy, an example of code will be useful :)

I've made an example with a custom constraint and it works as expected. I've tried to reproduce your behavior and I've seen that, if the error message defined in the custom constraint is a "constant" (look at the following example), only one error is returned. But if the error message is parametrized like "{value} is invalid" all errors are returned.

Code:
public @interface FooConstraint {
   String value();
   String message() default "is invalid";
//...
}


--
Kevin


Top
 Profile  
 
 Post subject: Re: Hibernate multiple cross-field validation of same type
PostPosted: Wed Mar 23, 2011 4:49 pm 
Contributor
Contributor

Joined: Mon Feb 28, 2011 7:27 pm
Posts: 20
Location: France
Just for completing my previous post :)

If only one error message is displayed when the error message is a "constant", it's because these constraint violations are considered equal (same message, propertyPath, validated value, ...).

--
Kevin


Top
 Profile  
 
 Post subject: Re: Hibernate multiple cross-field validation of same type
PostPosted: Wed Mar 23, 2011 11:05 pm 
Newbie

Joined: Tue Mar 22, 2011 9:16 pm
Posts: 2
Hi,

Thanks very much for the replies - my problem was having a constant value for the message.

Thanks!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.