Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Error codes from HibernateException

 
chets patel
Ranch Hand
Posts: 77
Eclipse IDE Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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 Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic