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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:02:36+00:00 2026-06-11T06:02:36+00:00

We are using hiberante,c3p0, postgresql for the persistent layer. While running data intensive jobs,

  • 0

We are using hiberante,c3p0, postgresql for the persistent layer.
While running data intensive jobs, mostly select/insert, one of the developers decided to use entityManager.flush() before commit , like so

entityManager.getTransaction().begin()
insert n elements
entityManager.flush()
entityManager.getTransaction().commit()

After a while all of the threads running the data intensive jobs were seemingly blocked, and we discovered they were waiting on database connections form the pool.
All the connections on the pool where in “Idle in transaction” state.
The situation could be replicated every time.

After removing flush() the situation disappeared.

Does anyone have any idea why would this happen?

Thanks 😀

  • 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-11T06:02:38+00:00Added an answer on June 11, 2026 at 6:02 am

    hibernate has an intelligent caching system which simply gathers a list of sql commands to execute and then it executes them upon commit. Flush serves to go ahead and partially execute these commands. It might seem that this would help, but when you consider that hibernate does not do anything until commit without flush, then you’re causing the database to have to deal with large transactions in short bursts rather than all at once.

    It would be the equivalent of handing over single sheets of paper to your work colleague to shred as opposed to letting him shred multiple sheets of paper at once. Combine this with the fact that the database may lock records in the middle of a transaction, from the moment you call flush the first time, the database dedicates itself to the task of executing commands until you commit. If the database isn’t waiting on you and has all the commands at once, it can finish in the time it takes to do the actual work.

    In short, hibernate knows what it’s doing. Flush overrides hibernate’s normal functioning and can actually diminish performance if you’re not careful. You should probably only use flush if order is important (such as performing deletion prior to insert).

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

Sidebar

Related Questions

we are running java6/hibernate/c3p0/postgresql stack. Our JDBC Driver is 8.4-701.jdbc3 I have a few
I'm using hibernate 3 with c3p0 for a program which constantly extracts data from
I'm facing a frustrating error while getting connection from mysql db. I'm using c3p0
We are using Liferay Portal 5.2.3 (with Hibernate and C3P0) on Tomcat 5.5.27, PostgreSQL
I'm running a Spring/Hibernate connecting to MySQL setup using c3p0 as my connection pool.
When using hibernate to retrieve data from Oracle 11g DB using either org.hibernate.dialect.Oracle10gDialect or
I am using Hibernate 3 version for my Application . While going through tutorials
I am using the JPA(hibernate) for the ORM and c3po for connection pooling. While
I'm using Spring 3.0.2, Hibernate 3.5.0 and c3p0 0.9.1.2 and I'm having a ton
I have an application that is using Hibernate 3, c3p0, and spring 2.5.6. We

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.