日期:2014-05-18  浏览次数:20607 次

hibernate 一对多查询问题
本帖最后由 xj33hf0331 于 2013-06-30 12:36:56 编辑
有两个表A 和B,通过ruleId关联,ruleId为A表主键,A表中有以下字段:ruleId,name age 等等,B表中有region字段,实体类 和映射文件中已经配置 了A与B的一对多关联关系,在A表中加了Set<B> regions字段,现在查询条件为name,age和b表中的region,如果不传region,name age传值  String,通过getHibernateTemplate().find(hql,list)查询,hql为"from a where name=? and age=?",查询没有问题。如果传region,hql为"from a where name = ? and age = ? and regions = ?",我吧regions传入一个set,结果抛了异常。请问这个查询要如果来做?

------解决方案--------------------

select a from a left join fetch a.regions r where a.name=? and a.age=? and r.region=?