-->
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: How to make hibernate load required objects
PostPosted: Tue Mar 11, 2008 11:31 am 
Newbie

Joined: Tue Mar 11, 2008 11:24 am
Posts: 2
Location: India
Hi all,
I am using Hibernate for ORM.
Right now i am monitoring my application using JProfiler.
Here, i run my application and monitoring instances which are not garbage collected.
In one flow of my application, i have found that hibernate is instantiating objects on the basis of available records in
corrosponding table.

For example, I have tried to load BaseListing class which is child of UserDtls and when i load
BaseListing like as given below (DAO layer code snippet).

baseListing = (BaseListing)getHibernateTemplate().load(BaseListing.
class, listingId);

Here, it loads baselisting with all its containing objects including UserDtls where returned UserDtls object is one
but in jprofiler it shows 32 UserDtls allocations (Instance Allocations, here UserDtls table has 32 records) whereas
in baseListing it has loaded only one instance.

So JProfiler shows me this 32 as a non-GCed objects.

Can anybody tell me that why hibernate is loading (creating instances of) UserDtls on the basis of available records into the UserDtls
even in baseListing it is assigning one instance of UserDtls.

(The mapping files are as given below)
i.e
I have two classes BaseListing and UserDtls.
Following is a configuration snippet of both
BaseListing.hbm.xml
<class name="test.BaseListing" table="base_listing" lazy="false">
.........................
<many-to-one name="userDtls" class="test.UserDtls" lazy="false">
<column name="USER_ID" />
</many-to-one
....................
</class>
</hibernate-mapping>

UserDtls.hbm.xml

<class name="test.UserDtls" table="user_dtls" lazy="false" >
...........................
<set name="baseListings" inverse="true" fetch="select">
<key>
<column name="USER_ID" />
</key>
<one-to-many class="test.BaseListing" />
</set<key>
....................
</class>
</hibernate-mapping>

Here,can any body tell me how can i make hibernate to load only required 1 instance
rather than unnecessary 32 instances of UserDtls.

Regards,
Manish

_________________
Manish


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 11:35 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Lazy load the UserDtls for BaseListing.

Code:
<many-to-one name="userDtls" class="test.UserDtls" lazy="true">
<column name="USER_ID" />
</many-to-one>


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.