-->
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.  [ 6 posts ] 
Author Message
 Post subject: Left join with criteria
PostPosted: Fri Dec 24, 2004 4:29 am 
Newbie

Joined: Fri Dec 24, 2004 4:09 am
Posts: 11
I have following tables and corresponding classes with appropriate get/set methods for all fields.

ITEMS
ID

ORDER
ID
ITEM_ID
CUSTOMER_ID

class Item{
privater long id;
private Set orders;
...
}

class ORDER{
privater long id;
private Item item;
private long customer_id;
...
}


Could anyone suggest a HQL query that selects all items that have no orders for given customer_id?

SQL query for this looks like

SELECT ITEMS.* FROM ITEMS LEFT JOIN ORDERS ON ITEMS.ID=ORDERS.ITEM_ID AND (ORDERS.CUSTOMER_ID = ? ) WHERE (ORDERS.ITEM_ID IS NULL) ;


Top
 Profile  
 
 Post subject: Re: Left join with criteria
PostPosted: Fri Dec 24, 2004 1:37 pm 
Newbie

Joined: Sun Nov 21, 2004 7:52 pm
Posts: 7
Location: Montr
I'm not quite sure, i can't see all your entities,

but you can try something like that:

select item from Item as item left join item.order as order where order.customer_id = :custId and isNull(order.item)

_________________
Hibernate user, trying to get the best of it.


Top
 Profile  
 
 Post subject: Re: Left join with criteria
PostPosted: Mon Dec 27, 2004 5:43 am 
Newbie

Joined: Fri Dec 24, 2004 4:09 am
Posts: 11
ledome20 wrote:
I'm not quite sure, i can't see all your entities,

but you can try something like that:

select item from Item as item left join item.order as order where order.customer_id = :custId and isNull(order.item)



I did not understand what else entities I need to describe
imagine there are not more entities. ;-)

provided query won't work even if it have correct syntax ;-)
like this one
select item from Item as item left join item.orders as order where order.customer_id = :custId and order.item is null;

It doesn't work because it puts criteria to where clause instead of join clause.

PS I still wounder if it _posible_ to put criteria in hibernate join clause?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 6:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Arbitary join conditions are not possible


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 6:48 am 
Newbie

Joined: Fri Dec 24, 2004 4:09 am
Posts: 11
Are there any plans to implement it in Hibernate3 or later?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 10:02 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, its very high on the TODO list for Hibernate3, once the new parser is stable.


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