Hi all, I have problem where I believe that Hibernate (using it with JPA :( ), is holding onto entities way too long.
Essentially this is the situation problem:
I have process, that needs to pull out a crap load of records (entities) from the database and update them all in one transaction. I have added paging logic so that it only pulls out one hundred at a time., captures the IDs of these of entities, and issue a sql native update for those objects..i.e. I do not modify the entity directly (i.e. hoping that Hibernate will unload it from its internal caching state).
From what I can tell, the entity reference count continues to climb regardless (based on visualVM), until the vm finally runs out of memory.
So..I am assuming that Hibernate/Caching is the culprit (an indeed in VisualVM, the references indecate it hibernate that holding the references). So I believe I need to either 'disable caching for this session/transaction (not even sure if that is possible), or potentially manually evict every entity pulled back. (this feels like it should not be needed as I would assume hibernate would/should only hold weak references to the entities, unless they become dirty?)
Does that sound correct? or am I missing something?
ps. psuedo code is:
Code:
transaction.begin()
while (!done)
List l = findEntities(startIndex,page_size);
foreach (entity : l)
ids.add(entity.getId()); // i.e. do NOT update state on the entity itself.
SQLUpdate('update x where id in('+ids+')'); // native update
transaction.commit(); // since no entities are modified..hibernate should be able to unload them? right?
Any feed back greatly appreciated.
Dan