我的HQL是这样。FROM Article AS art LEFT JOIN Category AS cat WHERE art.catid = cat.catid ORDER BY art.artid DESC请问怎么配置hbm映射?

解决方案 »

  1.   


    呵呵 LZ的玩笑开大了阿. HBM确实不能帮你做到left join on这种配置.只能生成实体Bean和相关的配置文件,.连多对多 一对多 都要自己去手动写了..LZ你只能自己在实现类里去操作了阿..
      

  2.   

    你的HQL跟你写配置有关系么~~~关系是实体和数据库表的映射!
      

  3.   

    用本地查询不好吗?为何非得用hql
      

  4.   


    如果想要用hql来left join,和配置是有关系的。
    那就是你必须配置这2个对象的关联关系!!!在Category.hbm.xml里
    <set inverse="false" cascade="all" name="articles">
          <key column="category_id"/>
          <one-to-many class="xxx.Articles"/>
        </set>hql写成
    from Category c left join c.articles a where .......
      

  5.   

    select c,a from Category c left join c.articles a where .......
    得到是list里的元素是Object[]型的,在这里就是[Category,Articles]
    可以Object[] row = (Object[]) list.get(i);
    Category c = (Category)row[0];
    Articles a = (Articles)row[1];