Rob
Rob

Reputation: 703

Hibernate Criteria - Novice question

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

Upvotes: 1

Views: 133

Answers (1)

fasseg
fasseg

Reputation: 17761

have you tried like this:

List<Activity> result =  session.createCriteria(Activity.class)
    .createCriteria("activityLocations") // this is the part that creates the join the parameter is named after the entity's property name
    .add(Restrictions.idEq("locationId"),locationId).list();

with locationId being the unique identifier of a ActivityLocation object.

hope that helped....

Upvotes: 1

Related Questions