I had the same issue. It seems there are two ways you can go about
doing this. Both ways involve grabbing the underlying hibernate
session/transaction objects and issuing commit/flush statements at a
predefined interval.
The trickiest part is actually figuring out where to pull the
hibernate session from, and it's done like this:
org.hibernate.Session sess =
(org.hibernate.Session)User.em().getDelegate();
Transaction tx = session.beginTransaction();
Now after you start off the transaction, instead of calling .save() on
your model directly, do this instead:
sess.save(new MyModelObject());
and then after x number of rows commit/flush/clear:
if(i % 100 == 0) {
tx.commit();
session.flush();
session.clear();
tx = session.beginTransaction();
}
Using this I was able to bring down insertion time from ~10minutes
down to about 30 seconds.
Also, if you are using Oracle (sequences) make sure to turn on sql
debugging and check if you are retrieving the sequence for each
insert. You don't generally want this as it will also add additional
overhead. Ideally you should have sequences/inserts grouped together,
not alternating.
Hope that helps.
> >
play-framewor...@googlegroups.com<play-framework%2Bunsubscribe@go
oglegroups.com>
> > .