-->
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: Help with HQL query
PostPosted: Tue Dec 19, 2006 7:27 pm 
Newbie

Joined: Tue Dec 19, 2006 7:23 pm
Posts: 4
Hi experts

I am new to Hibernate and think it is great.

I have a query and can't find how to write it in HQL.


Part Table
==========
part_id (key)
name

Product Table
==========
product_id (key)
title

Many to Many relationship primary product to part
Product_Part table is used to track the relationship but it is not an entity.

I Want to write the following HQL query.

I want to get the list of parts that are not in product 123.

In SQL I would write it like this:

select part.part_id from part, deployment_part
where part.part_id = product_part.part_id and product_part.product_id <> 123;

thanks,

Bob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 7:58 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
select p.id from Part p where p not in (
select dp from Part dp where dp.product.id = 123)

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject: Thanks for the help
PostPosted: Wed Dec 20, 2006 5:40 pm 
Newbie

Joined: Tue Dec 19, 2006 7:23 pm
Posts: 4
Thanks your reply got me on the right track, I ended up with:

from Part r where r not in
(from Part r2 where r2.products.id = :part_id)
order by r.name a

thanks again

Bob


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.