views:

29

answers:

1

Hi,

I am looking for some advice on what the best approach to a hibernate Criteria query is. I have been looking around for a while and can't decide if I should follow an approach of left Joins and searching for and ID or using the Query By Example API (I haven't found any good tutorials for this yet so if anyone has any suggestions it would be appreciated).

I have an Object - Activity that I have in session so can get any information about and I am looking to find similar activities based on certain fields.

An activity has :

  1. A Category (Object)
  2. A Provider (Object)
  3. A Set - ActivityLocations are an extended join table for activites and Locations

The area I am struggling with is how to query for activities at the same locations (but not nessecerily at all the same locations).

Thanks for reading and any help you can provide.

Cheers, Rob

A: 

have you tried like this:

List<Activity> result =  session.createCriteria(Activity.class)
    .createCriteria(ActivityLocations.class) // this is the part that creates the join
    .add(Restrictions.idEq("locationId"),locationId).list();

with locationId being the unique identifier of a ActivityLocation object.

hope that helped....

smeg4brains