Expressions in hibernate criteria

后端 未结 3 801
再見小時候
再見小時候 2021-01-12 22:59

Let\'s say I have a persistent class Item with a quantity field and a price field. Is there a way to build a Criteria that calculates the sum of quantity*price?

3条回答
  •  时光取名叫无心
    2021-01-12 23:43

    It is (probably) not possible to do it with Criteria. But HQL can be helpful for this.

    SELECT ent.quantity*ent.price from EntityName as ent WHERE ent.id = ?
    

提交回复
热议问题