Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.7
hello,
I have a general question.
I want to write a query similar to this.
sql query:
select count(Distinct userid) as users, truckid from unitofwork
where Zoneid='Z101' and truckid is not null
group by truckid
- what are my options ot handle this in hibernate.
1. I tried to do it using criteria...
but I felt its not supported to do this in this release, and can be done
may be in 3.0 and above.
2. tried to use the session.find as follows:
session.find("select uow.ngvTruck, count(uow.ngvUser) "+
"FROM com.voxware.orm.NgvUnitofwork as uow "+
"group by uow.ngvTruck");
this didn't seem to work, I was getting ORA-00979 error saying
its not a group.
my conclusion was, hibernate returns the whole object of ngvUnitof work
and not just the fields I am looking for and its not going to work.
3. so i tried to experiment with createSqlquery
and i am not having any luck or clue why its not working.
I get this error invalid column name
from this option.
session.createSQLQuery(
"select uow.uowstatus as {uow.uowstatus}" +
" FROM ngv_unitofwork {uow}" ,+
" WHERE uow.zoneid = 'Z101' " +
" group by uow.truckid ",
"uow", NgvUnitofwork.class) .list();
appreciate if you could guide me which direction to
follow,
is it possible to do a group by and count query in hibernate..2
an example of a group by..
yes I spent millions of hrs, looking through the forum,
trying various examples, but
doesn't seem to find a way out.
thanks