Using sum() in hibernate criteria

前端 未结 3 1034
猫巷女王i
猫巷女王i 2020-12-03 13:42

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

3条回答
  •  情话喂你
    2020-12-03 14:22

    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}));
    

提交回复
热议问题