0

Heej,

I'm working on a project where I should persist a lot of POJO files in to an Oracle database. The problem is that for each POJO Hibernate creates a new insert JDBC request. When persisting over 45.000.000 objects, this will take a really long time. I have to save data to a database and that data will be spread over 15 different tables. So for each set of data, I have to do 15 different insert statements. When I have to persist 3.000.000 data sets, 45.000.000 insert statements are needed.

When I was discussing this issue with a colleague, he suggested using CSV files instead of inserting each POJO with an insert statement. Now I'm wondering, is there an easy way of letting Hibernate write for each table a CSV file?

Or maybe someone does know a better solution?

4
  • 1
    In the end, the CSV files will need to be loaded and inserted in the database as well. What would you gain by first writing to files and then write the contents of the files to the database? Commented Jun 22, 2012 at 12:16
  • This bulk load utility will have to use insert statements as well. And I don't see why Hibernate would be faster at writing to an imaginary database using CSV files than writing to a real database. Where do these 3,000,000 data sets come from, BTW? Commented Jun 22, 2012 at 12:28
  • I thought using bulk load, you can write directly to the file system of the database. Letting Hibernate write to a file, I think, must me much faster than using a JDBC request, over the network and using SQL. Commented Jun 22, 2012 at 12:39
  • Possible duplicate of Using Hibernate to work with Text Files Commented Jun 3, 2016 at 3:02

1 Answer 1

-1

Suggest you read hibernate chapter on batch processing : http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/batch.html

Sign up to request clarification or add additional context in comments.

6 Comments

I did, many times. But there is nothing about doing one big insert. It tells only about controlling multiple actions.
Oh maybe i've misunderstood. I thought you were asking how to batch the insert statements, which you can do with the session. I guess you already tried that though ?
Yeah that's how it works now. But even if I batch all the insert statements, still for every object there will be in insert statement.
And what Id generation strategy are you using ( if using one ?? )
I select a sequence from the Oracle db. I hope I can change this to. But this sequence is used also by other users.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.