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: Groups of objects
PostPosted: Tue Mar 03, 2009 12:35 pm 
Newbie

Joined: Tue Jul 29, 2008 10:53 am
Posts: 11
Let's say I have this object (which is mapped)

Employee
----------------
ID
FirstName
LastName
Salary

There are a few employees:
1, John, Doe, 4000
2, Maria, Sharapova, 3500
3, John, Johnson, 3000
4, Theo, Huxtable, 4100

I want to get all distinct first names together with all employees who have that name. So I want to get a list like this:

Code:
John  - 1, John, Doe, 4000
      - 3, John, Johnson, 3000

Maria - 2, Maria, Sharapova, 3500

Theo  - 4, Theo, Huxtable, 4100


In other words, I would like to get a collection of First Names, and within each FirstName-object there should be another collection of employees.

I really have no clue which query to write for that. Is this even possible?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 6:13 am 
Newbie

Joined: Tue Jul 29, 2008 10:53 am
Posts: 11
I hoped the following would work:

Code:
ISQLQuery sql = sess.CreateSQLQuery(
   "select e1.FirstName as name, {e2.*} " +
   "from employees e1, employees e2 " +
   "where e1.FirstName = e2.FirstName ")
   .AddScalar("name", NHibernateUtil.String)
   .AddEntity("e2", typeof(Employee));

return sql.List();


But this only returns a long list of FirstNames combined with and employee object, like this:

Code:
John  - 1, John, Doe, 4000
John  - 3, John, Johnson, 3000
Maria - 2, Maria, Sharapova, 3500
Theo  - 4, Theo, Huxtable, 4100



Anyone has a clue how to solve this?


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.