In case, you haven't done it yet and since it seems like a simple Torque issue,
I think you'll get more Torque knowledgeable people on the torque-dev or
torque-user list over at db.apache.org :)

Sven Richter wrote:
> Hello David,
> 
> first of all, thanks a lot for your help.
> 
> I use the following function in the OM class of ProductInCategoryPeer
> (with the ID of a category as a parameter):
> 
>     *public* static *List* getProducts(*String* categoryId) *throws*
> TorqueException
>     {
>         int iCategoryId = *Integer*.parseInt(categoryId);
>         Criteria prodcrit = *new* Criteria();
>         prodcrit.setDistinct();
>         prodcrit.add(ProductInCategoryPeer.PROD_ID, 0,
> Criteria.GREATER_THAN);
>         *if* (iCategoryId != 0)
>         {
>             prodcrit.add(ProductInCategoryPeer.CAT_ID, iCategoryId);
>         }
>         prodcrit.addAscendingOrderByColumn(ProductPeer.PRODUCT_NAME);
>         prodcrit.setDistinct();
>         *return* doSelectJoinProduct(prodcrit);
>     }
> 
> 
> As you can see, I sort the results before I use setDistinct(). But it
> still doesn't work. The function still returns multiples. I already
> tried all possible orders of the lines above, but no change.
> 
> Am I doing something wrong?
> 
> Thank you very much,
> Sven.
> 
> David Pankros wrote:
> 
>>> ... According to the Torque manual, there is an option
>>> 'setDistinct()' that is supposed to prevent that. But it somehow does
>>> [not] work.
>>>
>>> Does anybody know, what I can do?
>>>   
>>
>>
>> IIRC in standard SQL, select distinct only works if the results are
>> sorted so that the duplicate entries will be next to each other in the
>> result set. (That may be DB specific. I can't remember for sure.)
>> Regardless, it may be affecting you here.
>>
>> I don't know much (if anything) about torque itself, but you may want to
>> try sorting in your query to get those duplicate entries to collapse,
>> while still using the torque setDistinct() option. In your example,
>> sorting by PRODCUT.ID would do it, but remember you also can't select
>> any rows from CATEGORY or PRODUCT_IN_CATEGORY (except maybe a count)
>> otherwise your rows will be no longer distinct and your problem will
>> remain.
>>
>> Hope that helps.
>>
>> Dave
>>

-- 
Raphaël Luta - [EMAIL PROTECTED]
Apache Portals - Enterprise Portal in Java
http://portals.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to