Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate Criteria query: finding matching records in a ManyToMany relationship  RSS feed

J. Cartwright
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a ManyToMany relationship between Content and Keyword entities (one Content instance contains a List of Keyword references). I'd like to find Content instances whose list of Keywords contains one or more of the Keywords in a provided list.

I can accomplish this with the following Criteria query if I provide a list of Keyword IDs rather than Keyword instances. It seems like there should be a way to be able to use the list of Keywords directly rather than have to create a separate list of IDs from it. Can someone please help me out?



Criteria criteria = getSession().createCriteria(Content.class);
Criteria keywordCriteria = criteria.createCriteria("keywords");
keywordCriteria.add("id", ids));

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!