I am attempting to batch load about a hundred thousand rows via hibernate. I have followed the advice in section 13 and am flushing and clearing the session every hundred rows. I have also disabled the second level cache for the Session.
Unfortunately, memory usage still increases rapidly as rows are inserted. Using jhat, I traced the memory use to references held to my persistent objects by the hibernate SessionImpl ActionQueue, as follows:
Code:
...skipped...
--> org.springframework.orm.hibernate3.SessionHolder@0x2aaab6113080[new] (54 bytes) (field transaction:)
--> org.hibernate.transaction.JDBCTransaction@0x2aaab6112bc8[new] (50 bytes) (field transactionContext:)
--> org.hibernate.impl.SessionImpl@0x2aaab60da3a8[new] (144 bytes) (field actionQueue:)
--> org.hibernate.engine.ActionQueue@0x2aaab60da440[new] (80 bytes) (field executions:)
--> java.util.ArrayList@0x2aaab60db888[new] (32 bytes) (field elementData:)
--> [Ljava.lang.Object;@0x2aaab8870240[new] (643856 bytes) (Element 70255 of [Ljava.lang.Object;@0x2aaab8870240:)
--> org.hibernate.action.EntityInsertAction@0x2aaab96273c0[new] (80 bytes) (field instance:)
--> my.persistent.Object@0x2aaab95fd7b8[new] (152 bytes)
The ActionQueue javadoc states that DML operations are queued until a flush. Since I am flushing the session periodically, I am uncertain why it is keeping these references:
Code:
[2007-11-11 02:12:34,624][DEBUG][def.AbstractFlushingEventListener] executing flush
[2007-11-11 02:12:34,624][DEBUG][jdbc.ConnectionManager] registering flush begin
...
[2007-11-11 02:12:34,626][DEBUG][jdbc.ConnectionManager] registering flush end
[2007-11-11 02:12:34,626][DEBUG][def.AbstractFlushingEventListener] post flush
Committing and restarting the jdbc transaction every hundred rows solves the memory issue -- after the commit, the persistent objects that have been flushed and cleared are garbage collected. However, obviously I'd like to be able to complete the batch load in a single transaction. Is it possible to do this with Hibernate, without memory use increasing without bounds as the number of rows increases?
Cheers,
Raman Gupta