[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-dev] MemoryLeak by CursoredStream??

Hello,

I use eclipselink and it's very nice. Our backend DB is MSSQL. I have to run pagination to millions of records. It seems eclipselink doesn't support setFirstResult/setMaxRows Pagination about MSSQL.
https://wiki.eclipse.org/EclipseLink/Examples/JPA/Pagination
Using above method, performance wasn't good because MSSQL pagination query(FETCH OFFSET) isn't used.

So, I tried to use CursoredStream as below. 
https://wiki.eclipse.org/Using_Advanced_Query_API_(ELUG)#Handling_Cursor_and_Stream_Query_Results
The problem is even if cursor.clear() is called, all record objects remain in UnitOfWork object as DescriptorEvent. I have to update records so "READ_ONLY" query hint can't be used.
===============================================
int max = 1000;
query.setHint(QueryHints.CURSOR, HintValues.TRUE)
		.setHint(QueryHints.JDBC_FETCH_SIZE, max);
CursoredStream cursor = (CursoredStream)query.getSingleResult();
while (cursor.hasNext()) {
	list = cursor.next(max);
	for (Object recordObj : list) {
		RecordEntity record = (RecordEntity)recordObj;
		doSomething(record)
		record.setSomeValue(someValue); // the record has to be updated
		entityManager.merge(record);
	}
	cursor.clear(); //cursor.releasePrevious() doesn't work as well
}
cursor.close();
===============================================
Is it possible paging records by CursoredStream without getting all records in memory? If anyone could tell me, it's really helpful.

Thank you,
Atsuo