-->
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: retrieving assembled objects with native sql
PostPosted: Fri May 19, 2006 9:33 am 
Beginner
Beginner

Joined: Tue Jun 28, 2005 4:33 pm
Posts: 21
Using a left join fetch in hql, I'm able to retrieve a list made up of parent objects, with a set of child objects nested inside of it.

However, when I try using native SQL (ether by .createSQLQuery() or a named query), I end up with a list of objects, each object containing the parent object, and standalone child objects (not nested in the parent object).

My hql is tuned to the point where it matches my hand written sql. I've read the references, the forums, the books, and looked through the Hibernate JUnit test code. I've tried using both <load-collection> and <return-join>; still no luck.

Is it possible to retrieve complete assembled parent objects (populated with collections of children inside them) using native sql or name queries; or must I manually assemble them? And if it is possible, could someone please post an example.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 3:31 am 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Have you found any information about this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 9:20 am 
Beginner
Beginner

Joined: Tue Jun 28, 2005 4:33 pm
Posts: 21
Actually, I have...

The SQL returns a list of objects. Each object is an object array. The first item in the array is the parent object, which does contain the populated collection. The second item, is one of the child objects (same hash code as the one in the collection)(your list will contain as many objects as there are in the child collection).

While it's simple enough then to just deal with object[0], you'll also have to watch out for memory leaks... A single parent object contains all the collection objects, and each object in the original list contains a reference to the parent object's collection. As long as the single parent object stays around, the list objects (as it stands) won't be garbage collected.


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.