Hi,
I'll try posting to the correct forum this time...
Having some blues trying to sort out how best to perform a particular query.
- I have a 'personcontainer' which contains a list of 'person'
- Each person has an 'organisation'
Diagram of the situation (no effort spared!):
(from:
http://www.flickr.com/photos/15331868@N02/1612476509/)
I need to find:
- a list of people **in a particular container** that match certain criteria in any of the main attributes of the organisation or the person.
Getting people in a particular container is fine:
Code:
session.createFilter(personcontainer.getPeople(), "")
.setFirstResult(startRecord)
.setMaxResults(itemsPerPage)
.list();
Getting ALL people matching certain criteria in any of the main organisation or person attributes is also fine:Code:
Criteria criteria = session.createCriteria(Person.class);
criteria.createAlias("organisation", "o");
Disjunction disjunction = Restrictions.disjunction();
Criterion firstNameCrit = Restrictions.ilike("firstName", searchTerm, MatchMode.ANYWHERE);
Criterion lastNameCrit = Restrictions.ilike("lastName", searchTerm, MatchMode.ANYWHERE);
Criterion orgNameCrit = Restrictions.ilike("o.name", searchTerm, MatchMode.ANYWHERE);
Criterion orgTelCrit = Restrictions.ilike("o.telephone", searchTerm, MatchMode.ANYWHERE);
disjunction.add(firstNameCrit);
disjunction.add(lastNameCrit);
disjunction.add(orgNameCrit);
disjunction.add(orgTelCrit);
criteria.add(disjunction);
criteria.list();
BUT HOW??? do I get people matching the criteria JUST contained in the container?
I really appreciate any help you can give.
James.