GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes How to show friendly message when getting unique constraint exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to show friendly message when getting unique constraint exception" Watch "How to show friendly message when getting unique constraint exception" New topic
Author

How to show friendly message when getting unique constraint exception

daphna deutsch
Greenhorn

Joined: Nov 17, 2005
Posts: 17
I'm using JPA with hibernate and oracle DB.

I add unique annotation to my entity:




As i understand, this validation will not occure at runtime.
i do have contraint in the DB.

so when trying to save an object, i'm getting the exception


How can i show a "friendly" message to the user instead of the message from the exception?
(like in the case of not-null, where i define the message on the entity).

lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
did you try adding



to web.xml

In the JSP you can have If then else ...



lavnish.blogspot.com
daphna deutsch
Greenhorn

Joined: Nov 17, 2005
Posts: 17
I might have more then one unique constraint in the same entity, and i want to show the user a specifc message about the problematic field.
lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
Try iterating over the exception class
http://docs.oracle.com/javase/6/docs/api/java/sql/SQLException.html#iterator%28%29

The doc says
Returns an iterator over the chained SQLExceptions. The iterator will be used to iterate over each SQLException and its underlying cause (if any).


 
GeeCON Prague 2014
 
subject: How to show friendly message when getting unique constraint exception