How can I write the sql query select sum(amount * direction) from transactions
into hibernate criteria ?
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}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With