Skip to content
Advertisement

JPA with HIBERNATE insert very slow

I am trying to insert some data to SQL Server 2008 R2 by using JAP and HIBERNATE. Everything “works” except for that it’s very slow. To insert 20000 rows, it takes about 45 seconds, while a C# script takes about less than 1 second.

Any veteran in this domain can offer some helps? I would appreciate it a lot.

Update: got some great advices from the answers below, but it still doesn’t work as expected. Speed is the same.

Here is the updated persistence.xml:

And here is the updated code part:

Updated, here is the source for MyRow:

Advertisement

Answer

To enable JDBC batching you should initialize the property hibernate.jdbc.batch_size to between 10 and 50 (int only)

If it’s still not as fast as expected, then I’d review the document above paying attention to NOTE(s) and section 4.1. Especially the NOTE that says, “Hibernate disables insert batching at the JDBC level transparently if you use an identity identifier generator.”

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement