-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Session Memory Management
PostPosted: Sat Feb 27, 2010 1:47 pm 
Newbie

Joined: Fri Nov 25, 2005 4:44 pm
Posts: 12
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


Top
 Profile  
 
 Post subject: Re: Session Memory Management
PostPosted: Sat Feb 27, 2010 4:02 pm 
Newbie

Joined: Fri Nov 25, 2005 4:44 pm
Posts: 12
after some more poking around, I found this:

EntityManager.clear(); // removes all entities from the current session.

as such changing the code above to (fixed the problem). still feels like the GC should have been able to free up these entities, instead of me being required to force the session to release it references.

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.
  getEntityManager().clear();
  SQLUpdate('update x where id in('+ids+')'); // native update

transaction.commit(); // since no entities are modified..hibernate should be able to unload them? right?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.