This is what I came up with:
Code:
session = HibernateUtil.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
for(int i =0;i<accountsToSave.size();i++){
session.saveOrUpdate(accountsToSave.get(i));
session.flush();
session.clear();
}
tx.commit();
Can I get an opinion? This is supposed to handle batch insert/update.
If one fails, the entire transaction should rollback.
Also,
when I tried to add:
Code:
if(i %20==0){
session.flush();
session.clear();
}
this gives me a NonUniqueObjectexception. I understand that the same object is being saved, but Am I supposed to use a new session for each object?