• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to show friendly message when getting unique constraint exception

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).



 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic