-->
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: HQL: illegal attempt to dereference collection
PostPosted: Sun Jun 19, 2011 6:18 pm 
Newbie

Joined: Tue Aug 24, 2010 7:24 am
Posts: 9
The situation is like this:

I have an entity Book that holds a one-to-many relationship with Chapter.

Now if I try the query,
Code:
from Book book inner join book.chapters chapter where chapter.title like '%hibernate%'
, it gives me the desired result.

But if I try,
Code:
from Book where book.chapters.title like '%hibernate%'
, I get the error illegal attempt to dereference collection.

The thing is that I only want the collection of Book objects in return and not a collection of pair of Book and Chapter objects in return which I get with the former query.

Could someone help me understand?


Top
 Profile  
 
 Post subject: Re: HQL: illegal attempt to dereference collection
PostPosted: Mon Jun 20, 2011 2:13 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Use 'select book' together with the first query:

Code:
select book from Book book inner join book.chapters chapter where chapter.title like '%hibernate%'


Top
 Profile  
 
 Post subject: Re: HQL: illegal attempt to dereference collection
PostPosted: Mon Jun 20, 2011 2:27 am 
Newbie

Joined: Tue Aug 24, 2010 7:24 am
Posts: 9
Yes, it worked. Many 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.