本质上,您需要创建一个别名并使用该别名来查询子集合,如下所示:
List questions = sess.createCriteria(Question.class) .createAlias("Tags", "t") .add( Restrictions.eq("t.name", "hibernate") ) .list();我假设在这种情况下,您实际上没有代表“桥接”表到标签表的类,否则您需要创建2个别名,例如:
List questions = sess.createCriteria(Question.class) .createAlias("QuestionTag", "qt") .createAlias("qt.Tags", "t") .add( Restrictions.eq("t.name", "hibernate") ) .list();您可以从文档中找到更多信息:
http://docs.jboss.org/hibernate/core/3.6/reference/zh-
CN/html/querycriteria.html#querycriteria-
associations



