-->
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: Loading and Garbage Collection of EntityClasses by Hibernate
PostPosted: Sun Feb 20, 2011 9:04 am 
Newbie

Joined: Sun Feb 20, 2011 8:55 am
Posts: 6
Started learning hibernate a few days back. Was wondering about something. I wanted to know the lifecycle of the entity classes? Specifically when are they loaded and when are they garbage collected?

1>When we start an application, or the first time we open a hibernate session the COnfiguration factory would take care to load all the entity classes into memory based on the configuration files.Am i wrong here? or are the entity loaded only as and when required based on lazy initialization property?

2>However I would like to know if this happens, when are the entity classes garbage collected? if the application holds no references to the entity classes outside the DAO layer, are the entity classes garbage collected on closing the session? Just like it happens with jdbc ResultSet objects on closing a jdbc connection?

3> If so does it mean, on consequent opening of a session, all the entity classes loaded again?

Would appreciate any help, and I apologize before hand if the question or my understanding is stupid.


Top
 Profile  
 
 Post subject: Re: Loading and Garbage Collection of EntityClasses by Hibernate
PostPosted: Mon Feb 21, 2011 8:54 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
1. You must distinct classes from instances.
Yes, all the entity classes(!) are loaded into memory, when the SessionFactory build's up the metadata-information.
And yes, entity instances(!) are loaded only as and when required based on lazy initialization property.

Classes are loaded by a class-loader and remain usually in memory unless the JVM is in risk of running out of memory.
In this situation during the GC, the GC may unload unused classes again.

Entity instances indeed are garbage collected in the same way as any other common java object,
that means the are garbage collected when there is no more reference pointing to the object instance.
In other words: Once you clear the persistent context or close the session,
entity instances are free to be garbage collected if you don't refer them anymore from your application.

>>3> If so does it mean, on consequent opening of a session, all the entity classes loaded again?
No. Neither classes nor entity instances are loaded, only by opening a new session again.


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.