给Hibernate多对多(一对多)集合属性的条件

public class ZgtcAirportIndexColunm extends BaseEntity implements java.io.Serializable {
private Set<AoRole> roles = new HashSet<AoRole>(0);
public Set<AoRole> getRoles() {
return roles;
}

public void setRoles(Set<AoRole> roles) {
this.roles = roles;
}
}

在查询ZgtcAirportIndexColunm 的时候,要给roles设置条件,需要
final String hql = "select z from ZgtcAirportIndexColunm z inner join z.roles as r where 1=1 and r.id in (:ids)";
如上方式设置
return indexColunmDao.getHibernateTemplate().executeFind(
new HibernateCallback<List<ZgtcAirportIndexColunm>>() {

@Override
public List<ZgtcAirportIndexColunm> doInHibernate(
Session arg0) throws HibernateException,
SQLException {
Query query = arg0.createQuery(hql);

query.setParameterList("ids", roleIds);

return query.list();
}
});

猜你喜欢

转载自liyixing1.iteye.com/blog/1946938