• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 42024
916
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.
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic