-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL: Selecting a component which contains a collection
PostPosted: Tue Mar 27, 2007 11:04 am 
Newbie

Joined: Tue Mar 27, 2007 10:09 am
Posts: 2
Hi,

I'm trying to write a HQL query which will return a component object (Address) which contains a collection of Strings (nonspecificAddressLines), which are by default lazily fetched. I would like this collection to be join fetched in the query.

If I just select the entity (Account) which is the ultimate parent of Address, there's no problem. The query looks like this

Code:
from Account account
left join fetch account.person.contactDetails.address.nonspecificAddressLines
where account.id = ?


So, I would have thought that just selecting the Address would have been as simple as the following:

Code:
select account.person.contactDetails.address
from Account account
left join fetch account.person.contactDetails.address.nonspecificAddressLines
where account.id=?


Unfortunately, it doesn't work. I get the following exception:

Code:
org.springframework.orm.hibernate3.HibernateQueryException: query specified join fetching, but the owner of the fetched association was not present in the select list


If I leave out the left join fetch, the nonspecificAddressLines collection remains null. It doesn't even get a PersistentList stub.

Ok, so I have a vague idea what's going on here, I think. You need to have an entity in the select clause for hibernate to correctly execute the query necessary to populate the collection.

What I want to know is, is there any workaround? Is there any way I can construct a single query which will return an Address object with a fully populated nonspecificAddressLines collection? I know I could just get the Account entity and pull the address from that, but I'd rather keep that work in the query if it's possible in order to be consistent with my approach for other queries.

Thanks,

Mark

Edit: I should say that I'm using Hibernate 3.2.2


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.