SELECT AVG("...") with Criteria API
I'm having difficulties with translatin开发者_如何学JAVAg following SQL syntax into Criteria API:
SELECT AVG(dbo.Member.Points) FROM dbo.Member WHERE dbo.Member.PaidMemberRegDate IS NOT NULL;
I have a Member class with a Points property. I just want to get the average Points of all Members that have the property PaidMemberRegDate set to null.
You should be able to use Projections to take care of this:
Criteria criteria = session.createCriteria(dbo.Member.class)
.setProjection(Projections.avg("Points"))
.add(Restrictions.isNotnUll("PaidMemberRegDate"))
Change the values around to match your class and associations and that should do it.
精彩评论