• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Bean Validation never executed

 
Markus Schmider
Ranch Hand
Posts: 132
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I am trying to test a Java Bean Validation custom constraint with JPA
I am using Wildfly 8.2










The AdressValidator.isValid method is never being called. What's wrong???

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Markus Schmider wrote:The AdressValidator.isValid method is never being called. What's wrong???

Your code example seems very similar with this article. The only difference is that the article uses a custom constraint validator on an entity and yours example uses an embeddable. Could you try adding the @Valid annotation where you are using your custom @ValidAdress annotation. That might trigger your validation provider to validate the adress which will then call your @ValidAdress validator. So the code would look like

Another (unrelated) note: why are you not using the FIND_ALL constant when defining the named query?

Hope it helps!
Kind regards,
Roel
 
Markus Schmider
Ranch Hand
Posts: 132
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
Adding the Valid Annotation has not solved the problem (although it seems logical to add it ...)
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Markus Schmider wrote:Adding the Valid Annotation has not solved the problem (although it seems logical to add it ...)

Honestly I expected that would do the trick, but it didn't. So I'm a bit clueless, so that means guessing and trial & error will be next

Which version of JPA/Hibernate are you using? I assume that regular bean validation does work (e.g. @Size(min=2, max=50)). It would be nice if you could create a small custom bean validation, apply it to the entity itself (instead of with an embeddable) and see if that works. If it does, we can assume it's embeddable related. If it doesn't, we can assume it's related to custom bean validation in general.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic