-->
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: Data From several Tables
PostPosted: Mon Mar 15, 2004 3:28 pm 
Newbie

Joined: Mon Mar 01, 2004 9:49 pm
Posts: 13
Hi,
Would like to know, if I am doing it right.

I want to get data from different tables, LOCATION, STATE, COUNTRY. I have Location object, which composes Country, State objects.

I dont want to use lazy initialization as most of the time I want information from all the objects but not the entire object.

mapping:
<class name="com.test.data.Location" table="loc">
<id name="locationId" type="string" column="loc_id">
<generator class="assigned"/>
</id>
<property name="locationName" column="loc_name"/>
<many-to-one name="country" column="country_id"/>
<many-to-one name="state" column="state_id"/>
</class>
<class name="com.test.data.Country" table="country">
<id name="countryId" column="country_id">
<generator class="assigned"/>
<id>
<property name="countryName" column="country_name"/>
<property name="attr1" column="attr1"/>
<property name="attr2" column="attr2"/>
<property name="attr3" column="attr3"/>
</class>

<class name="com.test.data.State" table="state">
<id name="stateId" column="state_id">
<generator class="assigned"/>
</id>
<many-to-one name="country" column="country_id"/>
<property name="stateName" column="state_name"/>
<property name="attr1" column="attr1"/>
<property name="attr2" column="attr2"/>
<property name="attr3" column="attr3"/>
</class>

lets say, I need location Name, state Name , and Country Name though the objects has lot more data in them.

This is how, I am doing:

Iterator iter = sess.iterate("select loc.locationName, st.stateName, ct.countryName from Location loc join loc.state st join loc.country ct);
List res= new ArrayList();
while (iter.hasNext()){
Object[] row = (Object[])iter.next();
LocLightWeight locLtWt = new LocLightWeight();
locLtWt.setLocName((String)row[0]);
locLtWt.setStateName((String)row[1]);
locLtWt.setCtryName((String)row[2]);
res.add(locLtWt);
}

I feel like, there could be a better approach than this.. is there any..?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 9:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No.
The better approach is to get the full object an use the second level cache for such basic data

_________________
Emmanuel


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.