开发者

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开发者_StackOverflow社区 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


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....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜