-->
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, many-to-many lists and join
PostPosted: Wed Jun 02, 2004 9:08 pm 
Newbie

Joined: Tue Nov 11, 2003 6:31 pm
Posts: 8
In Hibernate 2.1.2, I am trying to make a join query such as this :

Code:
select cat from Cat as cat left join cat.colors[0] as col order by col.name

Here is the associated mapping :

Code:
<class name="Cat" table="CAT">
  <id ... />
  <list name="colors" table="CAT_COLOR">
    <key column="CAT_ID" />
    <index column="IDX" />
    <many-to-many column="COLOR_ID" class="Color" />
  </list>
</class>

<class name="Color" table="COLOR">
  <id ... />
  <property name="name" type="string" />
</class>

I have searched through the documentation and it looks like the only coherent syntax. But it does not work.
I also tried theses syntaxes :
Code:
select cat from Cat as cat left join cat.colors as col order by col[0].name

and
Code:
select cat from Cat as cat left join cat.colors as col where index(col) = 0 order by col.name

But none of these are accepted by Hibernate, the problem being obviously the indexed collection.

I would like to know if Hibernate supports this kind of queries and how to write it in HQL.

I would have expected it to translate to this SQL :
Code:
select cat from CAT as cat left join CAT_COLOR as cat_color on (cat_color.cat_id = cat.id AND cat_color.idx= 0) left join COLOR as color on cat_color.color_id = color.id order by color.name


The same query without the [0] works well but of course does not have the join on the collection index in the generated SQL.


Thanks in advance


William


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.