-->
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: Initializing lazy collections in an HQL Query
PostPosted: Wed Jan 24, 2007 1:05 pm 
Newbie

Joined: Wed Jan 24, 2007 12:48 pm
Posts: 5
Hibernate version: 3.2GA
DataBase: postgresql 8.1.5
Hi all,

I need some advice I have this object: Parent who has a collection of children, pretty much like this:

Code:
class Parent {
  ...
  List getChildren() {
  }
  ...
}


Children collection is lazy, and I want to write an HQL query to initialize the parentalong
with his children:

I've tried 2 solutions.
First:
Code:
from Parent as p inner join fetch p.children


But this wont return any Parent without children.
I've also tried:

Code:
from Parent as p left outer join fetch p.children


But this would result in repeated Parent's on the list (once for every child).

Is there any other way of achieving this? Am I missing something?

Thanks in advance,

Miguel.

edit: I missed the fetch part of the second query


Top
 Profile  
 
 Post subject: Found various comments on the reference about this
PostPosted: Wed Jan 24, 2007 4:15 pm 
Newbie

Joined: Wed Jan 24, 2007 12:48 pm
Posts: 5
Well they were really about the second approach:

http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#objectstate-querying-executing

At the last part of the section it says:

Quote:
Note that queries that make use of eager fetching of collections usually return duplicates of the root objects (but with their collections initialized). You can filter these duplicates simply through a Set.


I guess this is far more efficient than a simple query and then initializing the collections at hand with Hibernate.initialize...

But particularly I would love this to work with inner joins, but I guess it doesn't due to the nature of inner joins.

cheers,

Miguel


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.