Hello guys.
I've faced with a problem when querying with Hibernate Criteria in Grails.
Take a look:
def visitors = Client.withCriteria{
visits{
use ( TimeCategory ) {between('date',date,date+1.month-1)}
}
sizeGe("visits",params.from)
sizeLe("visits",params.to)
fetchMode("visits", FM.JOIN)
};
I need only those clients, which has number of visits in month between from and to bounds.
But now size* restrictions is being applied to all visits. So if client has one visit in this month, and visit in previous month. And if I set from=2, this client will be in result. But it should not be there.
//UPD: the thing as that sizeGe and sizeLe restrictions work not as I expect.
From my point of view they should be applied after between restriction, but they not.
For example:
def client = new Client();
client.visits.add(new Visit(date:'2010-03-16'));
client.visits.add(new Visit(date:'2010-05-16'));
client.visits.add(new Visit(date:'2010-05-17'));
client.save();
And then I want if:
- date = Date.parse('yyyy-MM','2010-05')
- params.from=2
criteria should return this client, and if
- params.from = 3
not return;
But it returns, because sizeGe is being applied to all visits, no matter which date it has.
// END UPD.
Let me know if smth still isn't clear.
Any help is appreciated.
Thanks, Vova.