-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using left join fetch in HQL
PostPosted: Thu Oct 09, 2003 11:21 am 
Newbie

Joined: Thu Oct 09, 2003 11:11 am
Posts: 5
Section 9.3 of the manual says

In addition, a "fetch" join allows associations to be initialized along with their parent objects, using a single select. This is particularly useful in the case of a collection.

from eg.Cat as cat
inner join fetch cat.mate
left join fetch cat.kittens

Which models exactly what I have, class A which has a one to one association with Adetails. And a one to many association with B.

So, my from looks like

from A
inner join fetch a.details
left join fetch a.someSet

Now, the docs say the join allows the associations to be initialized along with their parent object - but the result set comes back with several instances of A with the same identity, I have not inspected these to determine if each instance is loaded with the whole collection, or just one. I would tend to believe each has one.

The one to many assoication DOES have an order by, and I am using HQL's ability to set first row and max rows.

I see the same section has this information:
"Note also that the fetch construct may not be used in queries called using scroll() or iterate(). "

But I am not really doing a scroll or iterate - am I?

So I was wondering if this should work.

I was hoping to avoid submitting detailed code. Let me know if what I describe "should work" or if you know of some work arounds.

I would like to see my A "list" query use only one SQL statement - which is what the above join magic does - unfortunately the list contains multiple instances of the A objects with the same identity.

Thanks,
JS


Top
 Profile  
 
 Post subject: Re: Using left join fetch in HQL
PostPosted: Thu Oct 09, 2003 11:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
stewajc wrote:
But I am not really doing a scroll or iterate - am I?

You to tell, Does your code look like
Code:
session.find()
or
Code:
session.iterate()


Did you try the
Code:
select distinct a from A as a ...
?[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 12:22 pm 
Newbie

Joined: Thu Oct 09, 2003 11:11 am
Posts: 5
I use session.find(), but I have not tried the select distinct, that is something I was not aware of! That makes perfect sense. I will try and let post the results!

Thanks!
JS


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 9:56 pm 
Newbie

Joined: Sun Sep 14, 2003 2:15 pm
Posts: 4
I think I figured it out.

The details class, although logically modeled as one to one, was actually modeled like this:

<many-to-one
name="details"
class="ADetails"
column="details_id"
not-null="true"
unique="true"
cascade="all"
outer-join="true"
update="true"
insert="true"
/>

This was done to solve the nasty problem I had with getting a (I thought) simple one-to-one relationship - where the details entity lifecycle is completely dependent on the parent class.

I guess I will wait until Hibernate supports fetch on multiple x-to-many associations in a left join. Alternatively - I suppose I could reopen wounds and start farting around with the "logical" one to one I have in hibernate as many to one / unique.

JS


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 10:13 pm 
Newbie

Joined: Sun Sep 14, 2003 2:15 pm
Posts: 4
But of course I am wrong,

The docs say in 9.3

"Note that, in the current implementation, only one collection role may be fetched in a query."

The details in not modeled as a collection role. So, so much for my reasoning why it was not working.

I am unsure why it does not work.


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