db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vitzethum, Daniel" <Daniel.Vitzet...@gigatronik.com>
Subject AW: RE how to write a criteria involved with count, group
Date Thu, 08 Sep 2005 07:54:28 GMT
Hello,

> How can I write a criteria that is equivalent to:
> 
> SELECT USER_NAME, COUNT(USER_NAME) NUMOFUSERS
> FROM USERTABLE
> WHERE USER_ID = 0000
> GROUP BY USER_NAME;

>> I think it will be something like that in your usertablePeer.java
file
>> 
>> criteria = new Criteria();
>> crit.addSelectColumn("COUNT("+ USERNAME+")");
>> crit.add(USER_ID, 0);
>> crit.addGroupByColumn(USER_NAME);
>> List litems = doSelect(crit);


as far as I know, that proposal won't work. As soon as you change the
number of columns to be selected by using "addSelectColumn", the common
"doSelect" method will fail.

The reason is that Torque tries to populate java objects from the raw
select result and needs every and each column as declared in your schema
file.

You will have to use "doSelectVillageRecords", resulting in a list with
"Record" objects, and fill your OM objects by hand. In the case of a
count operation, that shouldn't be a problem.


HTH,

Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message