-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to get child columnvalue wen you execute parenttable qry
PostPosted: Thu Mar 16, 2006 10:49 pm 
Newbie

Joined: Mon Feb 06, 2006 12:25 am
Posts: 17
Hi All,

I want to display parent table columns and one child table column

example:
parent table
Customerid, customerName,

child table:
itemId(from child table) one customer can have many itemId.


When you use lazy="false" it affects the performance.

how can i get the child column even though lazy="true"

how will you load child objects when you execute hibernate query when the lazy="true";

my query returns list of parent rows. i need to get child column for eacn parent row...

how to get the child column without affecting the performance?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 11:25 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If you don't mind a little bit of java awkwardness, you could use this concept:
Code:
select cust, item.id
  from Customer cust
  join cust.Item item
When you run that HQL, hibernate can detect that id (which is itemId) is in the parent table, and won't even do the join! The thing you get back from that query will be an Object[2], so you'd use java code like this:
Code:
for (Object[] ret : qry.list())
{
  Customer c = ret[0];
  int itemId = ret[1];
  // do stuff with c and itemId
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 2:18 pm 
Newbie

Joined: Mon Feb 06, 2006 12:25 am
Posts: 17
can i use mapping xml files for these???


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 19, 2006 9:42 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You can define the query in your mapping file. You can also create a bean-type object from the results, if you want:
Code:
<query name="CustomerAndItemId">
  select new CustomerAndItemId(cust, item.id)
  from Customer cust
  join cust.Item item
</query>
Then you just need to create the CustomerAndItemId class. You don't need to map it anywhere, instances of it will be created by hibernate: the "select new" syntax does that.


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