开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜