-->
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.  [ 3 posts ] 
Author Message
 Post subject: Lazy collections + proxies
PostPosted: Fri Nov 21, 2003 8:37 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Hi,

Im having memory problems in my Hibernate application, so I decided to use lazy initialiaztion in ALL my collections. The memory consume was reduced, but it still was very high. I then decided to use proxies in ALL my classes, but the memory consume increased very much.

I thought that using proxies would force persistent objects not to load if I did not invocate any get method. As same as in lazy collections.

What am i doing (or thinking) wrong?

Thanks,
Joao Rangel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 6:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Not really loading object from DB does not means having less object in memory. Proxy objects are objects.
Proxying a collection reduce memory usage (1 proxy for n objects). Not the case of proxy objects.
Using not too long session is a good way to limit mem usage.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 9:37 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Also remember one thing: proxy is dinamically generated class which _extends_ the class you specified as "proxy" attribute. That means if you have a class CLZ with 40 long/int/Object properties and you declare your mapping like

Code:
<class name="CLZ" ... proxy="CLZ">


When you load an object from the database, first object of class CLZ is created - it is the proxy. It will never have any of your properties initialized and it is just waiting for you to call one of its methods. When you eventually call anything (getName() for example), the proxy loads and created the real object (and this is the second object of class CLZ which gets created) and delegates method call to it. And both of these objects have 40 properties (ok, for proxy object none of them is initialized). As result, number of _loaded_ objects easily doubles if you are using proxies. These 40 properties may take alot of space if you have really many objects.

As workaround you may use interfaces - this is discusses in "11.1. Proxies for Lazy Initialization"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.