如果想要用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 .......
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];
呵呵 LZ的玩笑开大了阿. HBM确实不能帮你做到left join on这种配置.只能生成实体Bean和相关的配置文件,.连多对多 一对多 都要自己去手动写了..LZ你只能自己在实现类里去操作了阿..
如果想要用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 .......
得到是list里的元素是Object[]型的,在这里就是[Category,Articles]
可以Object[] row = (Object[]) list.get(i);
Category c = (Category)row[0];
Articles a = (Articles)row[1];