db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Emminger <e...@ericemminger.com>
Subject Re: Question regarding Peers, Joins and Criteria
Date Tue, 13 May 2003 17:30:16 GMT
Derek

Derek Hardy wrote:
> Thanks for your assistance Eric.
> 
> I wonder if I could trouble you for one further piece of assistance that
> would also answer an earlier query for me.
> 
> Using your code below, I added a new line
> 
> Criteria crit = new Criteria();
> crit.addSelectColumn("count("+PropertyPeer.PROPERTY_ID+")");   // New line
> added by DH
> crit.addJoin(PropertyPeer.STORE_ID, PropertyStoresPeer.STORE_ID);
> crit.add(PropertyStoresPeer.OWNER_ID, 1);
> List results = PropertyPeer.doSelect(crit);
> 
> I get exactly the SQL I am trying to produce
> 
> SELECT count(Property.PROPERTY_ID)
>   FROM Property, Property_Stores
>  WHERE Property_Stores.OWNER_ID=1
>    AND Property.STORE_ID=Property_Stores.STORE_ID
> 
> But when it executes I get the following exception raised.
> 
> org.apache.torque.TorqueException: Only 1 columns exist!
> 
> I'm trying to count the number of rows that would be returned by the query
> rather than actually retrieving the records from the database.

Torque is expecting all columns to be present in the results so it can 
map the results to objects. For this purpose, you need to use

List results = PropertyPeer.doSelectVillageRecords(crit);

Look at the Village docs for more info.

Eric


Mime
View raw message