users@glassfish.java.net

Re: BULK INSERTS EJB3

From: <glassfish_at_javadesktop.org>
Date: Sun, 25 Nov 2007 22:47:31 PST

Basically how do I do this in EJB3 using CMT

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
   
for ( int i=0; i<100000; i++ ) {
    Customer customer = new Customer(.....);
    session.save(customer);
    if ( i % 20 == 0 ) { //20, same as the JDBC batch size
        //flush a batch of inserts and release memory:
        session.flush();
        session.clear();
    }
}
   
tx.commit();
session.close();
[Message sent by forum member 'priyasubu' (priyasubu)]

http://forums.java.net/jive/thread.jspa?messageID=247101