-->
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: Navigating many-to-many relations in HQL
PostPosted: Fri Dec 12, 2003 12:04 pm 
Newbie

Joined: Tue Nov 18, 2003 11:56 am
Posts: 16
I'm migrating from Castor to Hibernate and have a question about how to navigate many-to-many-to-many relations in HQL.

The datastructure of my application is like this:

Item -- Collection -- Acl -- Role -- User

(all relations are many-to-many).

Now, in Castor I could write something like:

SELECT i FROM Item i WHERE i.id = $1 AND i.collection.acl.role.user.username = $2

in order to retrieve all items that a particular user has access to.

When I try something similar with Hibernate I get this error message:

net.sf.hibernate.QueryException: expecting 'elements' or 'indices' after: acl

Here is the Hibernate query that fails:
select i from Item as i where i.id = ? and i.collection.acl.role.user.id = ?

Is it possible to navigate through more than one many-to-many relation in Hibernate? If so, how? The database I use is MySQL 4.0.

Thanks
Per Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2003 12:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try explicit link via inner join

from a inner join a.collection b inner join b.role c ...

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 10:43 am 
Newbie

Joined: Tue Nov 18, 2003 11:56 am
Posts: 16
Thanks - that worked!

Per Thomas


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.