把代码都贴上来吧。如果要查询product列表,sql语句应该类似于select * from Product where com_id=?,如果在ProductHibDAO实现,方法应该类似于findList(CompanyBean  com)怎么会是findByExample(Product instance)呢?至于hql,where后的参数换成<many-to-one>中的配置就行了,这样的问题可以看看hibernate文档。

解决方案 »

  1.   

    ProductHibDAO中的方法如下:
    public List findByExample(Product instance) {
      log.debug("finding Product instance by example");
      try {
        List results = new ArrayList();
        // 按条件默认查询
        Criteria criteria = getSession().createCriteria( "com.daqin.gridouter.data.vo.Product").add(Example.create(instance));
        results = criteria.list();    return results;
      } catch (RuntimeException re) {
        log.error("find by example failed", re);
        throw re;
      }
    }ProductBO中的方法如下:
    public List getProductDefault(){  ProductBean product = new ProductBean();
      CompanyBean company = new CompanyBean();
      company.setId("001");
      product.setCompany(company);  List defaultList = this.getProductDAO().findByExample(product);
      return defaultList;
    }