Well, I dont see a reasons for why not use HQL in this case. If I am not mistaken this query below is actually an HQL query. I have tested this query with different classes here and it seems to have worked.
select s.Id, s.Name, sum(q.PointsObtained), sum(q.TotalPoints) from Student s join s.Questionnaire q group by s.Id, s.Name order by (sum(q.PointsObtained) / sum(q.TotalPoints)) desc sds On Tue, Apr 6, 2010 at 12:34 PM, Diego Mijelshon <[email protected]>wrote: > An alternative is to dynamically create the query portion of the HQL. > It's not as clean as Criteria, but it would work. > > Diego > > > > On Tue, Apr 6, 2010 at 12:08, Husain <[email protected]> wrote: > >> It is going to be a shame if the Criteria API cannot do this. My own >> implementation of IProjection would take me some time as I am still >> fairly new to NHibernate. >> >> Can anyone else help me with this? I'd appreciate any help. >> >> Husain >> >> >> >> On Apr 6, 5:19 pm, Diego Mijelshon <[email protected]> wrote: >> > It makes sense then... in that case, you'll have to either use >> SqlProjection >> > or implement your own IProjection. >> > That would be interesting to see so, if you do that, please share :-) >> > >> > Diego >> > >> > On Tue, Apr 6, 2010 at 09:58, Husain <[email protected]> wrote: >> > > The query I posted is a simplified version of what I am trying to do. >> > > In my application the WHERE clause is constructed by various filters >> > > as per the user's selection. So using the Criteria API gives me the >> > > cleanest and most readable code. I'd have to bend over backwards to >> > > get a dynamically generated HQL query. >> > >> > > On Apr 6, 4:13 pm, Diego Mijelshon <[email protected]> wrote: >> > > > I don't think the Criteria API is well suited for this*... maybe you >> can >> > > > make it work with SqlProjection, but it would be ugly. >> > > > Is there any reason why you want to use Criteria and not HQL in this >> > > case? >> > >> > > > Diego >> > >> > > > *: I might be wrong. Maybe there's a way to do it, but I don't know >> it. >> > >> > > > On Tue, Apr 6, 2010 at 08:09, Husain <[email protected]> >> wrote: >> > > > > Hi, >> > >> > > > > I am trying to build a report query using Criteria API. The query >> in >> > > > > HQL which is pasted below gives me the correct results. >> > >> > > > > select s.Id, s.Name, sum(q.PointsObtained), sum(q.TotalPoints) >> > > > > from Student s >> > > > > join s.Questionnaire q >> > > > > group by s.Id, s.Name >> > > > > order by (sum(q.PointsObtained) / sum(q.TotalPoints)) desc >> > >> > > > > How can I write the ORDER BY bit of the HQL in Criteria API? >> > >> > > > > Thanks, >> > > > > Husain >> > >> > > > > -- >> > > > > You received this message because you are subscribed to the Google >> > > Groups >> > > > > "nhusers" group. >> > > > > To post to this group, send email to [email protected]. >> > > > > To unsubscribe from this group, send email to >> > > > > [email protected]<nhusers%[email protected]> >> <nhusers%[email protected]<nhusers%[email protected]> >> > >> > > <nhusers%[email protected]<nhusers%[email protected]> >> <nhusers%[email protected]<nhusers%[email protected]> >> > >> > >> > > > > . >> > > > > For more options, visit this group at >> > > > >http://groups.google.com/group/nhusers?hl=en. >> > >> > > -- >> > > You received this message because you are subscribed to the Google >> Groups >> > > "nhusers" group. >> > > To post to this group, send email to [email protected]. >> > > To unsubscribe from this group, send email to >> > > [email protected]<nhusers%[email protected]> >> <nhusers%[email protected]<nhusers%[email protected]> >> > >> > > . >> > > For more options, visit this group at >> > >http://groups.google.com/group/nhusers?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<nhusers%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/nhusers?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- Humberto C Marchezi --------------------------------------------------------- Master in Electrical Engineering - Automation Software Consultant and Developer at the Town Hall of Vitória -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
