-->
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.  [ 13 posts ] 
Author Message
 Post subject: Query on a Hierarchy
PostPosted: Mon Dec 06, 2004 7:00 am 
Beginner
Beginner

Joined: Wed Aug 18, 2004 10:03 am
Posts: 28
Hi,

I have a Hierarchy. The super class is A, and child class are A1, A2 and A3. I need get all instances of A1 and A2, but i don't have an interface between A and A1, A2.

Any idea ?

I make a query with a 2 exists() sentences into where condition, but is very slow for my intention.

best regards
epsino


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 9:07 am 
Beginner
Beginner

Joined: Wed Aug 18, 2004 10:03 am
Posts: 28
I solve this with next HQL query:

from A
where
exists(
from A1
where A1.id = A.id
)
or exists(
from A2
where A2.id = A.id
)
and not exists(
from A3
where A3.id = A.id
)

The problem is that this query is very heavy, i need better performance.

Can you help me ?

regards
epsino


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 9:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
1- what about
from A1

then

from A2

?

2- are you using discriminator strategy? if yes, check class keyword in the reference guide

3-
Code:
select a
from A a, A1 a1, A2 a2
where a = a1
or a = a2

should work?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 11:27 am 
Beginner
Beginner

Joined: Wed Aug 18, 2004 10:03 am
Posts: 28
1. This solutions is not sufficient for me.

2. Are you using discriminator strategy? if yes, check class keyword in the reference guide

I use discriminator strategy, but i don't know how to use it with HQL.

3. This solution not work.

Thank you for all...

regards
epsino


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 12:24 pm 
Beginner
Beginner

Joined: Wed Aug 18, 2004 10:03 am
Posts: 28
Thank you !!!

I found how to use class keyword in HQL. This is the solution that i hope.

Thanks for all Hibernate Team, this is a greate, GREATE ORM.

regards
epsino


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 12:42 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
3. This solution not work.


please explain me what is the error, i use something like this i should work

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Re: Query on a Hierarchy
PostPosted: Thu Feb 03, 2005 1:02 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
You can do amazingly fast queries on hierarchies if you use the nested set theory.

See here:

http://www.intelligententerprise.com/00 ... o1_1.jhtml

With this method, you can for intance, get all children of a parent in a single SQL statement.

I have implemented this completely in hibernate if you need any help.

_________________
On the information super B road


Top
 Profile  
 
 Post subject: Re: Query on a Hierarchy
PostPosted: Thu Feb 03, 2005 1:05 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
Paul Newport wrote:
You can do amazingly fast queries on hierarchies if you use the nested set theory.

See here:

http://www.intelligententerprise.com/00 ... o1_1.jhtml

With this method, you can for intance, get all children of a parent in a single SQL statement.

I have implemented this completely in hibernate if you need any help.


when I said children, I meant descendants by the way, so for instance, if you have a hierarchy with 1000 nodes, the nested set way of doing things allows you to find all descendants of, say, the root node, in one SQL statement.

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 10:33 am 
Beginner
Beginner

Joined: Wed Aug 18, 2004 10:03 am
Posts: 28
3. This solution not work.

please explain me what is the error, i use something like this i should work

I probe it, and not happend an error, but the result is not the expected result. The result are empty. Maybe i probe it wrong... i test it and reply to you later...

regards
epsino


Top
 Profile  
 
 Post subject: Re: Query on a Hierarchy
PostPosted: Thu Jun 16, 2005 1:09 pm 
Newbie

Joined: Thu Jun 16, 2005 1:07 pm
Posts: 1
Paul Newport wrote:
You can do amazingly fast queries on hierarchies if you use the nested set theory.

See here:

http://www.intelligententerprise.com/00 ... o1_1.jhtml

With this method, you can for intance, get all children of a parent in a single SQL statement.

I have implemented this completely in hibernate if you need any help.


I would be interested in knowing how exactly you implemented this


Top
 Profile  
 
 Post subject: Re: Query on a Hierarchy
PostPosted: Fri Jul 01, 2005 6:46 am 
Newbie

Joined: Mon Jun 06, 2005 8:28 am
Posts: 5
Location: Germany
Paul Newport wrote:
You can do amazingly fast queries on hierarchies if you use the nested set theory.

See here:

http://www.intelligententerprise.com/00 ... o1_1.jhtml

With this method, you can for intance, get all children of a parent in a single SQL statement.

I have implemented this completely in hibernate if you need any help.


I would be interested too in knowing how you implemented the mapping. I already implemented SQL procedures get insert/remove tree nodes but I'm not sure about the proper way to do the mapping.
TIA, Martin

_________________
Cd wrttn wtht vwls s mch trsr.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 3:34 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
Found an interesting discussion on various techniques here:

http://www.dbazine.com/oracle/or-articles/tropashko4


Top
 Profile  
 
 Post subject: Re: Query on a Hierarchy
PostPosted: Mon Dec 18, 2006 4:50 pm 
Newbie

Joined: Mon Dec 18, 2006 4:43 pm
Posts: 1
Location: Pennsylvania, US
Paul Newport wrote:
You can do amazingly fast queries on hierarchies if you use the nested set theory.

See here:

http://www.intelligententerprise.com/00 ... o1_1.jhtml

With this method, you can for intance, get all children of a parent in a single SQL statement.

I have implemented this completely in hibernate if you need any help.


Any chance you still have the mapping files around for your implementation of nested sets. It would be much appreciated. I realize the original post is 2 years old, but I am having some trouble mapping the descendants collection.


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