Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Entity beans validation, how to know what constraint is being violated?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm doing some tests and I need to persist some entities.

I just wanted to know if, when I get a constraint validation error, there is some way to know what constraint is being violated?

I get this


It's really hard to know what constraint is being violated when you are persisting entities with a lot of attributes and containing other objects.. :S

Thanks for your answers!
 
Ranch Hand
Posts: 34
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frederico,

You just have to follow the javax.validation API on this, as the error message tells you: catch the exception and call getConstraintViolations() on it to iterate on the constraints your persisting entities don't respect.
Check the ConstraintViolation API for more information.

Christian Gossart
 
Federico Nafria
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christian,

I'm just starting to use jsr303 and I would like to know if you can point me some tutorial or book. I'm particularly interested in the business and data access layer..

Thanks again,

Federico Nafria.
 
Christian Gossart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Concerning JSR303, I cannot think of better tutorials than those of Emmanuel Bernard, who is the spec leader of this JSR. You can find them at Bean Validation Tutorials.
Also, the Java EE tutorial has a chapter on Bean Validation: Java EE tutorial.

JSR303 annotations can be part of your JPA entities, and bean validation can be triggered at any layer of your application, from the presentation layer to the data access layer.

Good reading


 
Federico Nafria
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I'll take a look.. ;)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic