Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Custom Bean Validation never executed  RSS feed

 
Ranch Hand
Posts: 153
3
  • 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???

 
Sheriff
Posts: 11338
178
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: 153
3
  • 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: 11338
178
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 {
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!