<!--考虑到 性能问题,请保持lazy的值为true,此时只能得到attachs中对象的Id值 ,若要得到其它属性值,请通过id再做查询-->
<set name="attachs" inverse="true" lazy="true" fetch="join">
<key>
<column name="TEXTID" not-null="true"/>
</key>
<one-to-many class="net.p5w.common.po.ircs.IrcsNewsAttach"/>
</set>
-----------------------------------------
public IrcsNews findById(Long ircsNewsId) {
IrcsNews news=this.ircsNewsDAO.findById(ircsNewsId);
if(!CollectionUtils.isEmpty(news.getAttachs())){
news.getAttachs().iterator().next();
}
return news;
}
通过粗体字的方法,返回的对象就已经加载了set中的对象。。