-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hierarchy Query Help
PostPosted: Sat Jun 13, 2009 12:07 pm 
Newbie

Joined: Thu Mar 30, 2006 2:10 pm
Posts: 14
NHibernate Version: 2.0.1GA

Hello,

I'm wondering if anyone could help me with the following scenario. I have a Employee class that has the following definition:

Code:
public class Employee
{
    public Employee ReportsTo { get; set; }
    public string Name { get; set; }
    public string Role { get; set; }
}


And the following employee structure:

Code:
Name: John Doe Role: President
`- Name: Jane Doe Role: Vice President
     `- Name: Simon Role: Managing Director
          `- Name: Bob Role: Sales Manager
              `- Name: Michael Role: Sales Rep
          `- Name: Ruth Role: Product Manager


I would like to create a criteria where I could pass the Employee object for John Doe (President) and retrieve all the Employees including Michael (Sales Rep).

Or in the event that I pass the Employee object for Jane Doe (Vice President) that I retrieve all the Employees excluding John Doe (President).

Any suggestions? Possible using ICriteria?

(I'm looking for suggestions, I do not have an hbm created)

Cheers,
Timothy Grant Vogelsang


Top
 Profile  
 
 Post subject: Re: Hierarchy Query Help
PostPosted: Mon Jun 15, 2009 9:10 pm 
Newbie

Joined: Thu Mar 30, 2006 2:10 pm
Posts: 14
Anyone?


Top
 Profile  
 
 Post subject: Re: Hierarchy Query Help
PostPosted: Tue Jun 16, 2009 12:59 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I'm using a SQL query in a similar scenario. Write the SQL you need fot that and wrap it in a hibernate SQL query.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Hierarchy Query Help
PostPosted: Tue Jun 16, 2009 7:40 pm 
Newbie

Joined: Thu Mar 30, 2006 2:10 pm
Posts: 14
Hello wolli, what does your query look like?

Cheers


Top
 Profile  
 
 Post subject: Re: Hierarchy Query Help
PostPosted: Wed Jun 17, 2009 2:34 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Code:
With ProjectTree( uid ) as
(
    select p.uid from sx.bus_project p where parentuid = :uid
    union all
    select p.uid from sx.bus_project p inner join ProjectTree t on p.parentuid = t.uid
)
select uid from ProjectTree


Have a look here for hierarchical queries:

http://msdn.microsoft.com/en-us/library/ms186243.aspx

_________________
--Wolfgang


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