I'm trying to add lots off records this way, max 10.000 at one time. Then a i do some other things and come here again with the same session. And do this again. Than i see my that my application get slower and finally stops with a java.lang.outofmemmory error.
I don't know 100% for sure. But i think it goed wrong here. I searched for some time and found only the remark that using the same session for so many records will cause this problem. So i wonder should i close the session after a while and get a new one or are there other solutions. Or maybe my code beneath contains an error.
Any help is appreciated.
try {
// start transaction
session.clear();
session.beginTransaction();
// iterate over alle the data items and save
for (int i = 0; i < dataList.size(); i++) {
session.save((MsconsDataBO) dataList.get(i));
}
// flush and commit
session.flush();
session.connection().commit();
} catch (Exception e) {
try {
// do rollback because of an error
session.connection().rollback();
} catch (Exception eSub) {
Import.errorExceptionExit("[couldn't perform rollback: mscons data]", e);
}
Import.errorExceptionExit("[couldn't add: mscons data]", e);
} finally {
log.debug("inserted " + dataList.size() + " records");
}[/u]
|