Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Spring Exception Handling Problem

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my DAO, I try to catch a generic Spring exception i.e DataAccessException for all type of DB problems. Then I wrap the message from it into my custom business exception.

But still, when I try to add a record with an existing primary key the application throws a stack trace of org.hibernate.exception.ConstraintViolationException without proceeding into the catch block of DataAccessException.

I even tried catching the most generic form i.e Exception. Here too, the application fails and throws the same stack trace. How can I catch this exception without failing the application.

I am using hibernate 3 with spring 2. The code which I am referring to is:



and the stack trace on this execution is:

 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have the PersistenceExceptionTranslationPostProcessordefined in your configuration. With JdbcTemplate it is there automatically, but with Hibernate you need to add it to your configuration

 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic