如何将sql查询select sum(amount * direction) from transactions写入hibernate条件?
select sum(amount * direction) from transactions
想我找到了答案。您必须使用Projection.sqlProjection()而不是Projections.sum()。例:
.setProjection(Projections.sqlProjection("sum(cast(amount as signed)* direction) as amntDir", new String[] {"amntDir"} , new Type[] {Hibernate.DOUBLE}));