Java P
Java P

Reputation: 2281

bulk insert using hibernate and sql server

I am using hibernate(3.3 vesion) with sql server 2005. I have to insert 100 thousands records in to database. Since I am using IDENTITY for primary generation strategy, I am not able do bulk insert in hibernate. I tried StatelessSession and couldn't gain any performance.

Could anyone please suggest a way to improve performance?

Please help.

Upvotes: 1

Views: 1586

Answers (2)

Olaf
Olaf

Reputation: 6289

Your main issue here is to prevent Hibernate from caching in memory all the records you are going to insert. If you only bulk insert records in your transaction, you can use StatelessSession. If you do other operations, for example record some statistics about the bulk load, you should call session.flush(), session.clear() after certain number of records, for example, every 10K records.

Upvotes: 0

NPKR
NPKR

Reputation: 5496

Use HibernateTemplate.saveOrUpdateAll(Collection entities) will give better performance.

Upvotes: 1

Related Questions