Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to show friendly message when getting unique constraint exception

 
daphna deutsch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you try adding



to web.xml

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


 
daphna deutsch
Greenhorn
Posts: 24
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic