在hibernate条件中使用sum() [英] Using sum() in hibernate criteria

查看:300
本文介绍了在hibernate条件中使用sum()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将sql查询从交易选择总和(金额*方向)写入hibernate条件?

How can I write the sql query select sum(amount * direction) from transactions into hibernate criteria ?

推荐答案

想想我找到了答案。您必须使用Projection.sqlProjection()而不是Projections.sum()。例如:

Think I found the answer. You must use the Projection.sqlProjection() and not Projections.sum(). Example:

.setProjection(Projections.sqlProjection("sum(cast(amount as signed)* direction) as amntDir", new String[] {"amntDir"} , new Type[] {Hibernate.DOUBLE}));

这篇关于在hibernate条件中使用sum()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆