需求,ssh框架中查询出的数据不在单一实体中,需要3表进行联合查询获取数据
在写sql后,需要进行设置别名的方式,把查询出的数据库字段与实体对应,注意,必须与实体名称相符并且区分大小写,还需要手动进行映射,否则查询数据为空
daoimpl中
public List getPlan(String mainId) { // Todo Auto-generated method stub Session session = getHibernateSession(); String sql="select distinct d.FD_ORDER,a.FD_ID as fdplanId,a.fd_landmark_id as fdLandmark,a.fd_cash_cate as fdCashCate,a.FD_REC_AMOUNT AS fdreceivables,c.fd_collected as fdCollected,c.fd_bad_debt as fdbadDebt,c.fd_unreceivable as fdUnreceivable,b.fd_invoiced as fdInvoiced,c.fd_this_return as fdThisReturn" + " from CN_CONTRACT_PLAN a LEFT JOIN CN_INVOICE_PLAN b ON a.DOC_MAIN_ID=b.DOC_MAIN_ID LEFT JOIN CN_CASH_DETAIL c ON a.DOC_MAIN_ID=c.DOC_MAIN_ID LEFT JOIN CN_CONTRACT_LANDMARK d on a.FD_LANDMARK_ID=d.FD_ID" +" where a.DOC_MAIN_ID=‘"+mainId+"‘"+" ORDER BY d.FD_ORDER"; //List<CnCashDetail> list=session.createsqlQuery(sql).addEntity(CnCashDetail.class).list(); List<CnCashDetail> list = (List<CnCashDetail>) session.createsqlQuery(sql) .addScalar("fdplanId",Hibernate.STRING).addScalar("fdLandmark",Hibernate.STRING) .addScalar("fdCashCate",Hibernate.STRING).addScalar("fdreceivables",Hibernate.DOUBLE) .addScalar("fdCollected",Hibernate.DOUBLE).addScalar("fdbadDebt",Hibernate.DOUBLE) .addScalar("fdUnreceivable",Hibernate.DOUBLE) .addScalar("fdInvoiced",Hibernate.DOUBLE) .addScalar("fdThisReturn",Hibernate.DOUBLE) .setResultTransformer(Transformers.aliasToBean(CnCashDetail.class)).list(); return list; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。