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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:59:40+00:00 2026-05-30T18:59:40+00:00

I am SO confused by sessions and transactions. I basically don’t see what the

  • 0

I am SO confused by sessions and transactions. I basically don’t see what the point of having both is, and I am very confused when to use one or the other.

What is the difference between an unflushed session and an uncommitted transaction?

I don’t even know how to ask what I don’t know… is there a resource that gives good examples of common session and transaction situations so I can see the difference?

  • 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-05-30T18:59:42+00:00Added an answer on May 30, 2026 at 6:59 pm

    A transaction in Hibernate is pretty much the same as a transaction in JDBC in general. When you get the Connection from the DataSource it defaults to autocommit=true, so for the transaction that’s changed to autocommit=false. That way changes get made in the database only when explicitly committed instead of each time you do an update.

    Hibernate’s Session does several things but in this case its function is as the 1st-level cache. It uses a concept called “transactional writebehind” for performance to queue up changes in that cache and only push them to the database when necessary. So for example if you retrieve a persistent instance and change it in a complex multi-method workflow where each method possibly makes no changes or several, only one update SQL statement is needed so Hibernate waits until necessary to aggregate them together. This is independent of whether you’re running in a transaction though – that always happens.

    Where the session cache and active transaction get together is flushing during an active transaction. Since Hibernate waits as long as possible to flush changes, if you’re not in a transaction and you flush, the changes become persistent in the database immediately. So that’s a performance optimization to reduce the number of database writes. But if you are in a transaction and you flush the session, you do push the changes to the database. But the database keeps the changes in its transaction queue. So even though they’re in the database, they’re not visible to other connections until you commit the transaction.

    Ideally there won’t be any explicit flushes, and the transaction commit will trigger a flush before the commit and that will both minimize the number of times you need to go to the database and keep uncommitted changes invisible to other callers. But you can flush as many times as you need.

    One thing that will cause Hibernate to flush automatically on your behalf is queries. As I said you can make many changes to persistent instances (even deleting them) and they’ll just be queued up in the session cache. But if you run a query (a dynamic finder, criteria, HQL, etc.) Hibernate can’t know if the queued changes will affect your query. So it’s pessimistic and flushes to be sure that everything’s consistent for the query. The database will use the flushed but not committed data for your query and return the expected results. This is the reason we recommend that you use the withNewSession method when doing queries in custom domain class validators so you don’t cause a flush of the current session during validation which can cause weird behavior.

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

Sidebar

Related Questions

I have two classes, basically one holds Members and the other Sessions. They are
I'm a little confused about the use of sessions for what I'm planning. A
One of the things that get me thoroughly confused is the use of session.Flush
confused - given a track uri, I can get one album but possibly more
Very confused here, trying out the yuicompressor on a simple javascript file. My js
When using Django sessions , is it good practice to see if session data
During one of my lab sessions I was given a problem related to delegates
I use CodeIgniter and save Sessions in my DB. The following line of code
I work for a php user authorization class and now I’m confused about sessions
I'm confused about the session states of SQL Server sessions. Can anyone explain it?

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.