users@glassfish.java.net

Re: BULK INSERTS EJB3

From: <glassfish_at_javadesktop.org>
Date: Tue, 04 Nov 2008 06:51:36 PST

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=314776