Kevin Meredith
Kevin Meredith

Reputation: 41939

Hibernate Code for Query

I found this Hibernate Criteria/Projection tutorial clear, concise and informative.

The author, A.P.Rajshekhar, says,

SELECT COUNT(ID) FROM ORDER  HAVING PRICETOTAL>2000 GROUP BY ID

Can be rewritten in Criteria query as follows:

List orders = session.createCriteria(Order.class)
     .setProjection( Projections.projectionList()
      .add( Projections.count(“id”) )
       .add( Projections.groupProperty(“id”) )
     )
      .list();

However, where does the HAVING PRICETOTAL>2000 show up in the Hibernate code? Is there a missing criterion (where clause in SQL) for this comparison?

Upvotes: 4

Views: 106

Answers (1)

ndtreviv
ndtreviv

Reputation: 3624

Yes. You also need:

.add(Restrictions.gt("priceTotal", 2000))

assuming the name of the PRICETOTAL property on the Order class is indeed "priceTotal"

Upvotes: 5

Related Questions