• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

sorting collection on fields of associated object?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having trouble coming up with a Criteria query that allows me to sort a list of objects based on the value of a field in another object that the objects being displayed have a reference to. Here's an example to clarify what I mean.

In my model, I have a Recruiter class:

public class Recruiter {
private Long id;
private String loginName;
}

There is also a Person class which associates a Person to a Recruiter:

public class Person {
private Long id;
private Recruiter recruitedBy;
private String lastName;
private String firstName;
}

In the GUI, there is a table that shows the Person's first and last names, and the login name of the Recruiter (person.recruitedBy.loginName).

The customer would like to be able to sort a list of Persons by the loginName of the recruiter, but I haven't been able to come up with a query that does that. This doesn't work:

query.addOrder(Order.asc("recruitedBy.loginName"));

At first, session.createFilter looked promising, but all the examples assume that I have a persistent object that has a lazy-loaded collection, like this:

session.createFilter( collection, "order by ...." ).list();

In my case there is no collection until I execute the query, so it doesn't look like createFilter will work for me.

If anyone has a pointer to a solution, I'd appreciate any help. Thanks in advance.

Steven Gollery
 
Steven Gollery
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it: just needed a nested criteria.
 
reply
    Bookmark Topic Watch Topic
  • New Topic