4

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?

1 Answer 1

5

Yes. You also need:

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.