Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Confused: No validator could be found for type
PostPosted: Fri Dec 09, 2011 12:32 pm 
Newbie

Joined: Fri Dec 09, 2011 12:30 pm
Posts: 2
Hi,
I am using the latest Hibernate Validator within Spring.

I have this annotated:

@Size(max=100)
@Valid
@Pattern(regexp=RegexLib.EMAIL_ADDRESS_PATTERN, message=RegexLib.EMAIL_ADDRESS_MSG)
@Override
public Collection<String> getEmailAliases() {
return proxiedUser.getEmailAliases();
}

When I validate it results in this: I thought this was supported?

javax.validation.UnexpectedTypeException: No validator could be found for type: java.util.Collection<java.lang.String>


Top
 Profile  
 
 Post subject: Re: Confused: No validator could be found for type
PostPosted: Sat Dec 10, 2011 7:22 am 
Contributor
Contributor

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

It's possible with Bean Validation to validate the content of any sub-type of Iterable by adding the @Valid annotation like you've done. In this case, the BV algorithm is then applied on each element (validation of the element constraints).

In your case the String class has no constraints. The @Pattern constraint you've added is applied to the Collection and not on each element of it. That's why you have this error message because the @Pattern constraint cannot be applied on a Collection.

Some ways to solve your problem:
  • create a custom constraint [1]
  • create a validator implementation for @Pattern (See BV spec 7.1.2) [2]

Hope this help!

[1] http://docs.jboss.org/hibernate/validat ... onstraints
[2] http://jcp.org/aboutJava/communityproce ... index.html

BTW, please use viewforum.php?f=9 for questions related to Hibernate Validator.

--Kevin


Top
 Profile  
 
 Post subject: Re: Confused: No validator could be found for type
PostPosted: Tue Dec 27, 2011 12:34 pm 
Newbie

Joined: Tue Dec 27, 2011 12:24 pm
Posts: 2
kevinpollet wrote:

Some ways to solve your problem:
  • create a custom constraint [1]
  • create a validator implementation for @Pattern (See BV spec 7.1.2) [2]

The first one is easier

_________________
blackberry developers


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.