一尘不染

在hibernate条件中使用sum()

hibernate

如何将sql查询select sum(amount * direction) from transactions写入hibernate条件?


阅读 476

收藏
2020-06-20

共1个答案

一尘不染

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

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