Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:33:38+00:00 2026-06-10T03:33:38+00:00

I am using Spring Hibernate integration in my application and DAO classes are extending

  • 0

I am using Spring Hibernate integration in my application and DAO classes are extending HibernateDaoSupport.
Suppose I save some object using the code
getHibernateTemplate().save(object);
As Spring Hibernate integration doesn’t mandate to write try-catch block, but suppose if any exception is thwron while saving that object.
Then what is the best way to handle it? I means should I catch it in the service layer and wrap it in some user defined excpetions.
Do I need to write try-catch in DAO layer method itself in case I want to log which method in DAO throws exception?

I have never used HibernateDaoSupport or Hibernate Template before so ignorant about exception handling. Please provide me your valuable inputs

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:33:40+00:00Added an answer on June 10, 2026 at 3:33 am

    The idea behind Spring using RuntimeException is that generally there are different types of exception:

    • Exceptions that you want to recover from (such as a DuplicateKeyException if a record that you’re trying to insert already exists or the more general DataIntegrityViolationException if there was a DB constraint that was violated as a result of user input)
    • Exceptions that you can’t recover from (the database is down)

    For the first case, you may well handle the exception (either through a custom business exception, so that the view layer can redirect to the input page and provide a meaningful message)

    For the second case, it would be easier to let the exception bubble up and have it handled by a generic exception handler that then displays a generic error page to the user. For this scenario it doesn’t make sense to wrap the exception in a custom exception as you won’t be able to recover. A blown up DB tends to be fatal.

    So what I would do:

    try {
       getHibernateTemplate().save(object);
    } catch (DataIntegrityViolationException dive) {
       throw new BusinessValidationException(dive, "You've got the data wrong");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Spring Hibernate integration in my application and DAO classes are extending
I have an application using Spring with Hibernate on a MySQL database. For some
I'm using Spring 3.1 and Hibernate 4 in a console application (i'm trying some
I am using Spring and JUnit to write some integration tests for my DAO.
I am using spring/hibernate stand alone application. if i dont configure Transactions i am
We are developing a web application using Spring framework and Hibernate ORM. As far
I am working on an application using Spring 3 and Hibernate 3.5 with Java
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
I am using Spring 3, JPA + Hibernate for a CMS application. In that
I'm writing some integration tests for a Spring/Hibernate app I'm working on, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.