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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:43:07+00:00 2026-05-15T15:43:07+00:00

I have a curious little problem. I have a service that needs to create

  • 0

I have a curious little problem. I have a service that needs to create 2000 records in the database, minimum on various tables. While it would be nice to have them run in the same transaction, the performance gets to be really bad around 400-600 inserts.

For some reason, the inserts go slower and slower. I suppose that Hibernate needs to do some kind of dirty checking… and as the object graphs get more and more complex, it stands to reason that Hibernate has more and more work to do.

This gets really bad because we have one service that basically imports 200 megs of XML data into the database, resulting in about 70,000 inserts. This takes about 1.5 hours to run.

So in Spring, is there a way where I can say, “Keep the hibernate session open, because we want lazy loading and stuff to work… but don’t put anything in a transaction?”

  • 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-15T15:43:07+00:00Added an answer on May 15, 2026 at 3:43 pm

    You should read the following Batch processing documentation from Hibernate. When you do things in a single transaction, they are all part of the same Hibernate session. None of your objects are persisted to the database until the session is flushed, so they are all kept around in memory. You need to periodically flush the session and clear it. The documentation gives plenty of details. If you really do not need all the semantics of a Hibernate session, use the stateless session interface.

    Also, make sure you are using the JDBC batching parameter. If you do not use it, then Hibernate will write a single row to the database at a time as opposed to writing multiple rows in batches. You may want to experiment with different batch sizes depending on your database and driver.

    Keep in mind that Hibernate has a lot of overhead associated with it for object tracking and dirty checking. If the performance with the tweaks does not meet your requirements, you may want to consider using your Hibernate mapping files to generate the raw SQL, but inserting the data using raw JDBC.

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

Sidebar

Related Questions

I have been using IoC for a little while now and I am curious
I have another rather curious problem. I have the following structure: CREATE TABLE [dbo].[Event]
I have a question that's not really a problem, but something that made me
I came across this problem while preparing for an interview and curious to know
As the title says, I am just a little curious...I have seen some European
I was a little curious to know that what is the difference between using
Recently I have come across a curious pattern in some code. We know that
So I have a little problem.I can't find how to save a bitmap file
I'm a little curious. I have a list of vimeo videos which I play
I have a curious question about efficiency. Say I have a field on a

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.