0

How to implement the following SQL query using Hibernate Criteria API:

SELECT
    SUM(field1) as s,
    SUM(field1 * field2) as m
FROM 
    table
Kaiser
  • 748
  • 7
  • 21

1 Answers1

1

Try

add(Projections.sqlProjection("sum(field1)) AS s", new String[] { "s" }, new Type[] {Hibernate.DOUBLE }))
add(Projections.sqlProjection("sum(field1*field2) AS m", new String[] { "m" }, new Type[] {Hibernate.DOUBLE }))
Rockstar
  • 2,228
  • 3
  • 20
  • 39