I am trying to insert or update a large data with Hibernate. I have a list contains 350k objects and when I use Hibernate saveOrUpdate()
, it takes hours to insert all the data.
I am using the code below for this operation. My development environment is JDK1.4 and Oracle Database.
public void saveAll(List list)throws HibernateException{
Session session = HibernateUtil.getEYSSession();
Iterator it = list.iterator();
int i = 0;
while(it.hasNext()){
i++;
Object obj = it.next();
session.saveOrUpdate(obj);
if (i % 50 == 0) { session.flush(); session.clear(); }
}
}
I am using batch update and also set hibernate.jdbc.batch_size
property 50 but it didn't help.
My object has one-to-one relation with another object so in this case using StatelessSession might be a problem. Because StatelessSession does not cascade to composed objects I think.
Do you have any ideas about how to increase the performance of saveOrUpdate()
operation in this case?
Thanks.