Reputation: 703
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 :
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
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