hibernate 多表查询sum总和

hibernate 用sql查询
String sql = "SELECT SUM(f.price) FROM rm_supplier as s, fi_final_pay_detail as f,fi_voucher_entry as v,fi_ledger as l where f.fpdCode = v.detailCode and f.ledgerId= l.ledgerId and l.isSettlement = 1 and f.supplierId = s.supplierId and f.submitStatus = 7 and f.price !=0 and f.costBelongTo = 1 and f.costName NOT IN ('定金','订金')
我目前是把几张表的字段创建了一个java实体类 但是查询的时候要把所有的字段查询出来 而且sum(f.price) 没有返回
求一个能在hibernate 中用的方法

首先,查询的时候只需要将你要的字段查询即可,不一定要全部;没写的其他字段是null,你这样写最好把select sum...这段用括号括起来

hibernate查询不是用表名,是通过类名查询

在实体类中增加一个属性s ,设置set和get方法 注解用@Transient,@Transient表示不是对应表中字段。写法如下,
private Long s;

@Transient
public Long getS(){
return s;
}
public void setS(Long s){
this.s =s;
}

我只需要 sum 的总和 别的不用 left 也不行啊

你这个sql貌似写的都不对..写之前先到数据库中运行一下,能查出东西在写道java中

比较麻烦的sql语句直接用jdbcTemplate执行会比较简单 用hibernate是在它能简化操作的情况下使用的