Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

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.. ;)
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!