This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Entity beans validation, how to know what constraint is being violated? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Entity beans validation, how to know what constraint is being violated?" Watch "Entity beans validation, how to know what constraint is being violated?" New topic
Author

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

Federico Nafria
Greenhorn

Joined: Sep 30, 2010
Posts: 9
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!
Christian Gossart
Ranch Hand

Joined: Mar 13, 2008
Posts: 34
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

Christian Gossart
Federico Nafria
Greenhorn

Joined: Sep 30, 2010
Posts: 9
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

Joined: Mar 13, 2008
Posts: 34
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

Joined: Sep 30, 2010
Posts: 9
Thanks!

I'll take a look.. ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Entity beans validation, how to know what constraint is being violated?