-->
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: populate a single object using multiple queries
PostPosted: Thu May 04, 2006 10:58 am 
Newbie

Joined: Wed May 03, 2006 4:34 pm
Posts: 6
Can anyone recommend an approach for populating an object with multiple queries? An object that does not map directly to a table and cannot be completely populated with a single SQL statement. For example, if I have an object that contains the following.

studentId
studentName
numCourses
avgGrade
lowGrade
highGrade

Assume that there is no way to return all this in one query. How can I populate some of the properties with one query and then populate the rest with another query?

Hibernate version:3.1.3


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 1:36 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It can't be done. However:

1) If all the tables in question are on the same server, then you can get them all back in one query (though it might be complicated): at the very worst, you can use a stored procedure to do the work.

2) You can use the <join> element to grab columns from other tables (see refdocs section 5.1.18).

3) You can use associations from the "main" object to other objects that are mapped separately. Then use delegation to add the other objects' methods to the main object. E.g.
Code:
public class MainClass ... {
  ...
  public int getValueA()
  {
    return getAssociatedObject().getValueA();
  }
  ...
}

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 10:57 am 
Newbie

Joined: Wed May 03, 2006 4:34 pm
Posts: 6
Yes, I think it would have to be done in a stored procedure to get it all at once. I want to avoid that, so I will be exploring the other options you recommended. Thanks.


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.