Hello,
I'm using Hibernate 2.14 and JBoss 3.24 and I'm trying to update a large number of objects (160000). I know that you shouldn't use Hibernate for something like this, but I would like test Hibernate a little bit. The problem is, that I'm always running out of memory.
The code (in a stateless session bean) looks like this:
Code:
public boolean massUpdate() {
try {
Session session = HibernateUtil.getSession();
HibernateUtil.beginTransaction();
int batch = 1;
Iterator fs = session.iterate("from foobar");
Foobar foobar;
while ( fs.hasNext() ) {
foobar = (Foobar) fs.next();
foobar.setValue(foobar.getValue()+5);
// flush ever thousand updates:
if (batch%1000 == 0) {
session.flush();
session.clear();
}
batch++;
}
HibernateUtil.commitTransaction();
}
catch (HibernateException e) {
HibernateUtil.rollbackTransaction();
e.printStackTrace()
}
finally {
HibernateUtil.closeSession();
}
return true;
}
Is there something wrong with the code?
Thanks a lot,
Jonas