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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:53:33+00:00 2026-06-17T16:53:33+00:00

I have a simple Hibernate query like: from MyEntity where name = ? Nothing

  • 0

I have a simple Hibernate query like:

from MyEntity where name = ?

Nothing fancy, but it’s called many times in a fairly big transaction (lasts one second, may load dozens or hundreds of entities). Profiler shows that a lot of time is spent in:

org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1240)
org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)

In other words – flushing changes before running the actual query.

Can I somehow prevent Hibernate from doing this flush at all?

If not, what can I do to make it faster?

  • 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-17T16:53:34+00:00Added an answer on June 17, 2026 at 4:53 pm

    By default hibernate flushes before issuing a query during a session (FlushMode.AUTO), and chews up lots of CPU time doing it. It is particularly painful if you have a session where many queries and updates run alternately.

    If the query is likely to select back data that you have inserted/updated/deleted during the current session then you need these flushes. This may also be the case even if you haven’t modified anything in the current transaction but are using a transaction-isolation level like read-uncommitted.

    Assuming you don’t want uncommitted reads, etc., there are two ways around this that I know of:

    1. Select everything you’ll need during the session before you make any modifications (ie., re-order things so that all your queries are issued before any modifications are made).
    2. If you know for sure that you are selecting data that has not been modified in this session then you can explicitly set the flush-mode to something which won’t trigger the flush, like this:

      Query query = session.getNamedQuery(SOME_QUERY_NAME);
      query.setFlushMode(FlushMode.COMMIT);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query like below select f.id, s.name, ss.name from first f left
I have a hibernate object called User which has a many-to-many relationship with another
I have a Hibernate/JPA query which performs a simple query based on an indexed
I have a simple Nhibernate Linq query that is returning more results than expected:
I have created very simple app with persistence context (hibernate as provider) to read
I have an extremely simple web application running in Tomcat using Spring 3.0.2, Hibernate
I was trying to configure spring 3.1 and hibernate. I have written a simple
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I have an NHibernate LINQ query like this: var maxNumber = session .Linq<Child>() .Where(c
It might be very simple but I think I am missing something. I have

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.