hi i have an application in which i first check the value in the DB table if not present generate a new value and insert into the DB,this loop goes around a million times,how can i speed it up??
in my working class:-
session=HibernateSessionFactory.getSession();
for(----loop
i check
i generate
then:-
MyTable myTable=new MyTable();
myTable.setName("dasdas");
myTable.setww("ss");
myTable.setaa("daaasdas");
hibernateRepositoy.save(dgCcno,session);
}
save method i the other class:-
public void save(Object obj,Session session) {
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(obj);
session.flush();
session.clear();
tx.commit();
}
catch (HibernateException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
if(tx!=null){
tx.rollback();
}
}
catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
how can i speed this up, or is this the right approach?
Added:- i cant use batch update, i have to insert the value right away, cause the values in the next select query can be the same.. and have to give the value from the DB then
1 Answer