-->
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: query with many-to-many association
PostPosted: Sat Nov 20, 2004 6:28 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
I have a many-to-many association, and i want to retrieve all the item ids that are in a list of categories.

I tried this:

"select item.id from Item item where elements(item.categories) in (:categories)";

and then..
List categories =...; // list of category objects
query.setParameterList("categories", categories);

But I have an exception with the jdbc driver ( i am using jaybird jdbc driver with firebird 1.5).


Top
 Profile  
 
 Post subject: Re: query with many-to-many association
PostPosted: Sat Nov 20, 2004 7:36 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
"select item.id from Item item where elements(item.categories) in (1)";

This produces the following SQL:

select n.ID
from Items n where
(
(select an.ID // INSTEAD OF select an.CATEGORY_ID!!!!
from ITEM_CATEGORY an
where n.ID = an.ITEM_ID)
in(1)
)



ITEM_CATEGORY TABLE is defined as

ID | ITEM_ID | CATEGORY_ID


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 21, 2004 6:25 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
This seems work:

"select n.id from Category a left join a.items n where a in (:args)"


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.