db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Hardy" <derek.ha...@teknosys.co.uk>
Subject RE: Question regarding Peers, Joins and Criteria
Date Tue, 13 May 2003 17:23:20 GMT
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.

Thanks again

Derek Hardy

-----Original Message-----
From: Eric Emminger [mailto:eric@ericemminger.com]
Sent: 13 May 2003 18:06
To: Turbine Torque Users List
Subject: Re: Question regarding Peers, Joins and Criteria


Derek

Derek Hardy wrote:
> Hi
>
> I'm trying to create a method in the PropertyPeer to reproduce the
following
> SQL query
>
> select *
>   from property p
>       ,property_stores s
>  where p.store_id = s.store_id
>    and s.owner_id = 1;
>
> How do I define the criteria to add a restriction on the join table.

Probably something like

Criteria crit = new Criteria();
crit.addJoin(PropertyPeer.STORE_ID, PropertyStoresPeer.STORE_ID);
crit.add(PropertyStoresPeer.OWNER_ID, 1);
List results = PropertyPeer.doSelect(crit);

Eric


---------------------------------------------------------------------
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