views:

31

answers:

1

Hello,

I'm having difficulties with translating 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.

+1  A: 

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.

Brian Riehman