-->
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: Query problem: Criteria, collections, filters?
PostPosted: Thu Oct 18, 2007 5:36 am 
Newbie

Joined: Tue Oct 09, 2007 4:48 am
Posts: 11
Hi,

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!):
Image
(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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 6:43 am 
Newbie

Joined: Tue Oct 09, 2007 4:48 am
Posts: 11
Sorry, posted in wrong forum.

I've re-posted in:
http://forum.hibernate.org/viewtopic.php?p=2367255.

James.


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.