Optimizing data inserts for HibernateTemplate
I have to optimize the database (especially insert) performance of a certain legacy tool. The tool has been written in Java and for the data access layer Spring + HibernateTemplate was the technology of choice.
The actual problem is doing some bulk inserts. We have to insert more than 50K data by calling HibernateTemplate.save() for each. This is apparently a very inefficient way but because of the lack of time, we cannot change the implementation for now.
What would be the optimization patterns other than changing the implementation?
Answers
The only things I can think of, if you want to optimize code without modifying the code are :
- try larger values for hibernate.jdbc.batch_size
- use a faster disk and machine for your database
If you're ready to slightly change the code, then follow the advices of the documentation, and regularly flush and clear the session while inserting your data. Or use a stateless session.