ssh框架中联合查询所取结果不在单一实体,sql写法

需求,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;
    }

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...