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.  [ 2 posts ] 
Author Message
 Post subject: Linking tables
PostPosted: Thu Nov 01, 2007 7:23 pm 
Newbie

Joined: Thu Nov 01, 2007 7:12 pm
Posts: 2
Hi,

I have two objects called product and order. Order has foreign key (one to many) relationship with product table. Order object has a field/column called status. I want to find out a unique list of products which has got order status set to 'Dispatched'. In other words status field is in the order table, so i want to link order and product tables on product id and find a unique list of products where order status is 'Dispatched'.

Any help is greatly appreciated.


Top
 Profile  
 
 Post subject: Re: Linking tables
PostPosted: Fri Nov 02, 2007 9:43 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
callorchat wrote:
Hi,

I have two objects called product and order. Order has foreign key (one to many) relationship with product table. Order object has a field/column called status. I want to find out a unique list of products which has got order status set to 'Dispatched'. In other words status field is in the order table, so i want to link order and product tables on product id and find a unique list of products where order status is 'Dispatched'.

Any help is greatly appreciated.


I'm going to assume it is actually a many-to-many relationship with Product since otherwise a given product could only be sold to one customer on one order. That being said you ask for a pretty simple HQL query:

"SELECT DISTINCT p FROM Order o INNER JOIN o.Products p WHERE o.Status = :status"

and then set your status parameter to 'Dispatched'.

If you mapped it with a one to many and a many to one mapping you'll just have to include the INNER JOIN to your intermediate object.

Hope that helps.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.