• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Custom Bean Validation never executed

 
Ranch Hand
Posts: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is sad to notice that documentation frameworks are not well documented. The solution to this issue is to have the right Target, in the case of the https://beanvalidation.org/2.0/spec/#constraintsdefinitionimplementation-constraintdefinition at the Class Level use "TYPE_USE for container element constraints"
for instance:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@Documented
public @interface ExtractedValue {
reply
    Bookmark Topic Watch Topic
  • New Topic