Hi
I have a session leaking (Oracle DB, Hibernate Search 3.3.0) after a manual re-indexing.
In my app I run a Lucene index update every 60 min using a Java thread
Indexing code:
Code:
private void batchIndex(Criteria query, Integer batchSize) {
Session session = null;
int batch = 0;
try {
session = getSession(); // using SessionFactoryUtils.getSession(sessionFactory, true)
FullTextSession fullTextSession = Search.getFullTextSession(session);
query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
.setCacheMode(CacheMode.IGNORE)
.setFetchSize(batchSize)
.setFlushMode(FlushMode.MANUAL);
ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY);
batch = 0;
while (scroll.next()) {
batch++;
fullTextSession.index(scroll.get(0)); //indexing of a single entity
if (batch % batchSize == 0) {
// commit batch
fullTextSession.flushToIndexes();
fullTextSession.clear();
}
}
// flush what is left
fullTextSession.flushToIndexes();
fullTextSession.clear();
// close to release closing DB open cursor
scroll.close();
} finally {
try {
// close to release JDBC connection
//closeSession(session); // using SessionFactoryUtils.closeSession
} catch (Exception e) {
logger.warn("AbstractIndexer.batchIndex - Exception while closing the Hibernate Session");
logger.warn(e);
}
}
logger.info("Indexing work completed for " + getIndexedClass() + ". " + batch + " entity indexed.");
}
Whenever the index is not updated (no db changes) I can see the jdbc connection being released:
Code:
2011-03-16 16:24:22 INFO indexer.AbstractIndexer -> Indexing work completed for class com.sapienza.dccm.model.entity.Document. 0 entity indexed.
2011-03-16 16:24:22 DEBUG jdbc.ConnectionManager -> releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2011-03-16 16:24:22 DEBUG jdbc.ConnectionManager -> transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
if there is a change (therefore an update to Lucene index) the JDBC connection doesnt seem to be returned back to the pool...
If I un-comment //closeSession(session) then the JDBC connection seems to go back to the pool but in this case (still figuring out why) my thread dies.
My question:
- why do I need to close the session manually in the second case only (index update is required) but doesnt seem to be the same in the first case?
Tnx in advance
Beppe