flush() + clear() does not work, as at least Hibernate does not store entries to the disk if you do this.
I had success with this code:
final UserTransaction tx = ctx.getUserTransaction();
tx.begin();
for (...) {
em.persist(wa);
if (0 == ++pos % BATCH_SIZE) {
tx.commit();
tx.begin();
}
}
tx.commit();
flush() and clear() made no difference, neither concerning memory nor speed.
[Message sent by forum member 'kurti' (kurti)]
http://forums.java.net/jive/thread.jspa?messageID=314775