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.  [ 4 posts ] 
Author Message
 Post subject: Sub tree selects
PostPosted: Thu Dec 01, 2005 4:38 pm 
Newbie

Joined: Mon Nov 28, 2005 11:15 am
Posts: 13
Hibernate version:3.0
Name and version of the database you are using:MySQL

Hi All,

I have a simple mapping of a Category Table with a Product Table.
A Category Table can have multiple sub categories. The Product Table has a FK reference to a Category.

Category:
ID NAME PARENT_ID
------------------------
1 foo null
2 bar 1
3 acme 2
4 apple 3

Product:
ID NAME CATEGORY_ID
-----------------------------
1 foo 3
2 bar 4
3 test 2

I would like to issue a query in hibernate to retrieve all Products that belong to a particular category or children of that particular category. This would I beleive require some sort of sub tree query.

Select p from Product where P.categoryId in (select category and children category ids that have a ancestor category id of 2)

Any help would be greately appreciated.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 5:23 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use CONNECT BY or SELECT WITH or RECURSIVE SELECT, depending what is available on your SQL system. Altnatively, search for "nested set sql" and have a look at the latest CaveatEmptor unit tests.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 6:04 pm 
Newbie

Joined: Mon Nov 28, 2005 11:15 am
Posts: 13
christian wrote:
Use CONNECT BY or SELECT WITH or RECURSIVE SELECT, depending what is available on your SQL system. Altnatively, search for "nested set sql" and have a look at the latest CaveatEmptor unit tests.


Hi Christian, I am using MySQL. I could not find a connect by clause in the same. Could you assist with an example? Thanks much.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 6:16 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Did you do the second part of my advice?


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