解决EJB懒加载问题

对于EJB懒加载时,由于没有hibernate中的opensessionview,那么需要在会话结束之前就加载数据,可以选择在dao层实现,代码如下:

 

public TBLDeliveryWarrant find1(String id) throws ServiceException {
try {
TBLDeliveryWarrant deliveryWarrant = deliveryWarrantDao.find(id);
Set<TBLGoods> goods = deliveryWarrant.getGoods();
if (goods != null && goods.size() > 0) {
for (TBLGoods good : goods) {
good.getCargoJT();
}
}
deliveryWarrant.getContainers().size();         //加载集装箱信息
deliveryWarrant.getGodownWarrant().getCode();  //加载单子对应的货物

return deliveryWarrant;
} catch (DAOException e) {
logger.error(e);
throw new ServiceException("", e);
}
}

posted @ 2013-06-13 10:54  若 ♂ 只如初见  阅读(300)  评论(0编辑  收藏  举报