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 8085219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:02:47+00:00 2026-06-05T18:02:47+00:00

In a Spring + Hibernate + JTA project I’m trying to get exception handling

  • 0

In a Spring + Hibernate + JTA project I’m trying to get exception handling working. For the following code:

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public HandsetManufacturer createHandsetManufacturer(
        HandsetManufacturer handsetManufacturer)
        throws HandsetManufacturerAlreadyExistsException{
    HandsetManufacturer handsetManufacturer2=new  HandsetManufacturer();
    try {

            handsetManufacturerDao.findByUniqueProperty(
                HandsetManufacturer.class, NAME_PROPERTY,
                handsetManufacturer.getName());
        throw new HandsetManufacturerAlreadyExistsException();
    } catch (BusinessObjectNotFoundException ignoreMe) {
    }
    //handsetManufacturer2= handsetManufacturerDao.create(handsetManufacturer);

    try{
        handsetManufacturer2= handsetManufacturerDao.create(handsetManufacturer);
    }catch (JDBCException e) {
        System.out.println("::HibernateException::"+e.getSQL());
        System.out.println("::HibernateException::"+e.getErrorCode());
        System.out.println("::HibernateException::"+e.getSQLState());
        System.out.println("::HibernateException::"+e.getSQLException());
        System.out.println("::HibernateException::"+e.getMessage());
        System.out.println("::HibernateException::"+e.getCause());
        throw new TechnicalException(e);
    }

    return handsetManufacturer2;
}

I’m trying to catch underlying hibernate/jdbc/db exceptions (for example when dependent entities are still present the remove will fail with a org.springframework.orm.hibernate3.HibernateJdbcException) and perform some actions. However the catch code is never reached.

But if i remove “@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)” from my method it will reach to catch block.
I guess this has to do with the way Spring manages this, but I don’t know just how I can catch exceptions during JDBCException and also use @Transaction annotation

Any help is appreciated!

  • 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-05T18:02:48+00:00Added an answer on June 5, 2026 at 6:02 pm

    I guess your DAO is also configured to have transaction with REQUIRED propagation. In Hibernate, there are lots of action delayed until the session is flushed. One of the timing that flush will happen is before transaction commit. That means if your method (I guess it is a method in some service) is having transaction around it, Hibernate persist or save actions in your DAO create() are not actually going to DB until finish of your service method.

    One workaround is explicitly perform a Session flush() (you may consider putting in DAO’s create() ), so that it will trigger DB update and hence cause exception you expect to be thrown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying integrate spring with hibernate but catch exception on project start. Caused by:
Eclipse is not recognising @Inject in my JSF-Apache Myfaces/Spring/Hibernate project. I am trying to
I'm using Spring with Hibernate as a JPA provider and are trying to get
I'm trying to combine Spring with Hibernate using Annotations and I'm getting the following
WHen deploying my Spring / Hibernate application, I get the following warning related to
At runtime an application (based on Java/Spring/Hibernate) throws the following exception: 07:18:38.511 ERROR Error
In my Spring + Hibernate project, I was doing logging by SLF4J 1.6.4 with
I am using Spring with Hibernate in my project.There are many methods written in
I have a project with spring and hibernate in GWT, I am using below
I'm trying to set up a Spring JPA Hibernate simple example WAR for deployment

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.