Using sum() in hibernate criteria

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

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

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 14:29

    I think what you need is formula. Something like this,

    @Entity
    @Table('TRANSACTIONS')
    Class transactions {
    
         @Column("AMOUNT")
         private double amount;
    
         @Column("DIRECTION")
         private double direction;
    
         @Formula("AMOUNT * DIRECTION")
         private double multiplication;
    
    }
    

    And add multiplication column to your projection list.

提交回复
热议问题