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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:40:13+00:00 2026-06-05T00:40:13+00:00

i have a java jpa/hibernate app that needs to get a lot of data

  • 0

i have a java jpa/hibernate app that needs to get a lot of data to perform its task. I encountered the n+1 problem, so i decided to use the hibernate.default_batch_fetch_size (@batchsize) property to lower the needed sql roundtrips. I tried some values but the performance crashed with nearly all tried values.

batchsize: 0 – sqls send: 14000 – duration: about 1 min

batchsize: 4 – sqls send: 5000 – duration: more than 10 min

batchsize: 10 – sqls send: 2700 – duration: about 5 min

batchsize: 100 – sqls send: 400 – duration: about 1 min

is this a “normal” behaviour? if not what can be the mistake?

I logged the generated sql with log4jdbc. I noticed that between every batched statement lied about 100-150 millsecs. If i run the sql later the runtime for each statement was no more than 20 millisecond. So this doesnt seam to be a DB (IN statement) related issue.

Java: 1.6.0_31, Hibernate 3.6.7, DB Postgres 9.1.1, JDBC postgresql-9.1-901.jdbc4.jar

thanks in advance

update
to make things clear: the performance loss is during batch fetching not batch update/ insert

  • 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-05T00:40:14+00:00Added an answer on June 5, 2026 at 12:40 am

    after some debuging i found the issue. Hibernate (at least in version 3.6.7) stores all mapped collections in a map. You can access these map with a snipplet like this:

    SessionImpl si = ((SessionImpl) entityManager.getDelegate());
    PersistenceContext persistenceContext = si.getPersistenceContext();
    persistenceContext.getCollectionEntries();
    

    So every collection creates one entry in this map.If you have pojos with lots of collections like in my case this grows large fast. For example 10.000 pojos loaded with each 32 collections you have 320.000 Collection entries. Hibernate now just iterates through the map (org.hibernate.engine.BatchFetchQueue.getCollectionBatch(CollectionPersister, Serializable, int, EntityMode)) to find not loaded Collection ids to put these later in the IN clause. Hibernate does not limit the search for the key to a certain typ of collection so this gets even worse.

    I guess i have to clean up some collections and hope hibernate gets a more efficent way to find the keys in higher versions.

    Update:
    this comment on hibernate jira might be interesting for someone with the same problem:
    https://hibernate.onjira.com/browse/HHH-1775?focusedCommentId=42686&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-42686

    Update:
    this issue was adressed in hibernate version: 4.1.8

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

Sidebar

Related Questions

I'm have a lot of time using hibernate (JPA) in java, but i recently
I have an app using Spring, JPA (Hibernate) and the Java validation framework (Hibernate
i have the following problem. I use Spring and JPA (Hibernate) to persist Data
When I look at Java frameworks like Hibernate, JPA, or Spring, I usually have
I have a standalone java application, which uses JPA for its persistence. Right now
I have a java web app running under Spring 2.5.6, Hibernate 3.4 (with Hibernate
Is it possible to perform date arithmetic using JPA/Hibernate? For example, I have an
I have a designed a back end solution with Java Hibernate and JPA. Now
I have a java web application built on Stuts2/Google Guice/JPA. It uses hibernate as
i have a strange situation: I'm using jpa/hibernate to get rows from a mySql

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.