While inserting many objects in a batch the application runs out of memory because the FullTextIndexEventListener for Lucene collects the updates. Is there a way to avoid this?
hibernate.cfg.xml
Code:
<event type="post-insert">
<listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
</event>
Inserting code something like:Code:
Session session = sessionFactory.openSession();
session.setCacheMode(CacheMode.IGNORE);
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Item item = new Item(...);
session.save(item);
if ( i % 100 == 0 ) {
session.flush();
session.clear();
}
}
tx.commit();
session.close();