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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:12:10+00:00 2026-06-17T18:12:10+00:00

As we all know that in Hibernate if no transaction commit, the changes won’t

  • 0

As we all know that in Hibernate if no transaction commit, the changes won’t affect in database. But I found something weird. And the code as follows:

ApplicationContext ctx = new ClassPathXmlApplicationContext("Spring.xml");
    SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory");
    Session session = sessionFactory.openSession();
    Model model = new Model();
    ...
    session.save(model);
    session.flush();
    session.close();

And the model was saved to database even there’s no transaction, anyone can explain this?
Any comments would be appreciated! Thanks!

PS: I am using mysql.

  • 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-17T18:12:12+00:00Added an answer on June 17, 2026 at 6:12 pm

    Hibernate doesn’t need transactions, the most common problems in database-based applications are just easier to solve with transactions which is why usually everyone uses transactions with Hibernate. But that’s mere coincidence/convention/laziness.

    All Hibernate needs is a java.sql.Connection and if your container provides one even though there is no current transaction manager configured, Hibernate is fine with that.

    In fact, Hibernate has no idea that there might be a transaction manager. So session.flush() will use the ApplicationContext to get a connection, generate the SQL and use JDBC to send the generated SQL code to the database.

    From Hibernate’s point of view, that’s all that happens.

    There can be several reasons why the data is committed to the database:

    1. You forgot to turn of auto commit on the connection.
    2. Your web container / spring config automatically wires a transaction manager that synchronizes with HTTP requests.
    3. Your code is called form another method which is annotated with @Transactional; in this case, you inherit the existing transaction.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As you all know, Hibernate introduces overhead to basically all operations on database due
We all know, that Spring MVC integrate well with Hibernate Validator and JSR-303 in
How to check that Hibernate mapping configuration matches database? I'd like know if I
Does nHibernate create code that has all the details of the column? I know
We all know that openId has become such a popular method for user authentication,
We all know that CSS sprite images are great to reduce the amount of
We all know that a hash table has O(1) time for both inserts and
We all know that most applications out there assume class names to follow the
as you all know that if we use flash object in web page in
as we all know that html_safe work in controller and view i am sending

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.