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

  • Home
  • SEARCH
  • 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 8844347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:27:51+00:00 2026-06-14T11:27:51+00:00

The project used Spring + Hibernate Sample code: public void method(){ try{ dao.saveA(entityA); //condition

  • 0

The project used Spring + Hibernate

Sample code:

public void method(){    
   try{  
     dao.saveA(entityA);  
     //condition may be throw RuntimeException;  
     dao.saveB(entityB);  
    }catch(RuntimeException e){  
     throw e;  
    }finally{  
      dao.saveC(entityC)  
    }  
}

Finally, just entityC will be saved in database in test.
I think saveA, saveB, saveC in the same transaction,they should not be committed.
In this case, I want to know why entityC is committed.
How does Spring do this in the finally block?

//————————-//
Actually, my question is that:how spring ensure the transaction committed in the finally block .
will Spring be get a new connection in the finally block?

  • 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-14T11:27:52+00:00Added an answer on June 14, 2026 at 11:27 am

    Spring has nothing to do with this, what you obtain is a behavior as required by JLS 14.20.2 Execution of try-catch-finally:

    A try statement with a finally block is executed by first executing the try block. Then there is a choice…

    • If execution of the try block completes abruptly because of a throw of a value V, then there is a choice:
      If the run-time type of V is assignable to the parameter of any catch clause of the try statement, then the first (leftmost) such catch clause is selected. The value V is assigned to the parameter of the selected catch clause, and the Block of that catch clause is executed. Then there is a choice…

      • If the catch block completes abruptly for reason R, then the finally block is executed…

    In your code snippet, RuntimeException corresponds to “value V” in above quote.

    Exception is thrown and caught in respective catch block, which then “completes abruptly” by re-throwing the exception – that is, throw e in your snippet corresponds to “reason R” in above quote.

    Then, as required by language specification, “finally block is executed”.

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

Sidebar

Related Questions

In my project I can successfully test database code. I'm using Spring, Hibernate, HSQLDB,
Spring is used in our team's Java EE project, and hibernate is used for
When I was working with java spring hibernate struts2 eclipse project. I used buildpath->
I am working in Java project with Spring and Hibernate framework. The database used
I have just started making a project using spring and hibernate. My DAO layer
I'm investigating presentation layers to be used with spring in our new project. I'm
In my C# project,I used the following code to access my form outside its
I'm trying to make a project using struts 2, spring 3 and hibernate, but
We have been using Spring Remoting in our project for sometime. It is used
The project I am working with uses JSF + Spring + Hibernate. This is

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.