• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

SQL Error codes from HibernateException

 
Ranch Hand
Posts: 77
Eclipse IDE Tomcat Server Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using spring with JPA (Hibernate Implementation). I want to do mapping of vendor specific SQL error code to my user defined messages. Spring throws DataAccessException. I am not able to retrieve SQL error code from DataAccessException.
I tried somethink like this:


Spring is providing some SQLErrorCodeTranslator using sql-error-code.xml. but it is working with jdbcTemplate. I want to use jpaTemplate.

Thanks in advance.
 
author & internet detective
Posts: 41502
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DataAccessException has a number of subclasses such as DataIntegrityViolationException. If you want one of those, just catch the lower level exception. No need to parse error codes.

If you are looking for an error type that's not a subclass, look at getMessage() or getCause() to get more detail about the exception.
 
chets patel
Ranch Hand
Posts: 77
Eclipse IDE Tomcat Server Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeanne
Thanks for your reply.
I tried catching dataIntegrityViolationException. But issue is, it gives me message that "can not execute JDBCBatchUpdate". If I have unique constraint on more than two columns and I want to display explanatory message to user then it is very difficult for me to do this.
Can you please let me know how can I handle this situation.

Thanks in advance.
 
reply
    Bookmark Topic Watch Topic
  • New Topic