You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andrus Adamchik <an...@objectstyle.org> on 2015/11/09 12:25:49 UTC
Re: Counting distinct related objects using EJBQL
It's a bug in Cayenne. I just opened a Jira: https://issues.apache.org/jira/browse/CAY-2037 . While we are working on fixing it, there's a woraround described in Jira - if possible use a unique attribute of the target object inside COUNT. E.g. a.shop.name (if no such attribute exists, map ID as an ObjAttribute, and use that).
Andrus
> On Oct 30, 2015, at 2:45 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
> Hi all, and a very happy Friday to you.
>
> How would I go about counting distinct related objects using EJBQL? If I want to count the number of “Shops" related to “Receipts", I’d expect to be able to do use EJBQL like this, which works fine for regular attributes:
>
> SELECT count(distinct a.shop) FROM Receipt a
>
> However, this generates the incorrect SQL
>
> SELECT COUNT(DISTINCT *) AS sc0 FROM smu.fd_receipt t0 INNER JOIN smu.fd_shop t1 ON (t0.shop_id = t1.id)
>
> Any ideas? I’m using the 4.0M3-SNAPSHOT release.
>
> Cheers,
> - hugi
Re: Counting distinct related objects using EJBQL
Posted by Hugi Thordarson <hu...@karlmenn.is>.
Thanks Andrus—the workaround works fine :)
Cheers,
- hugi
> On 9. nóv. 2015, at 11:25, Andrus Adamchik <an...@objectstyle.org> wrote:
>
> It's a bug in Cayenne. I just opened a Jira: https://issues.apache.org/jira/browse/CAY-2037 . While we are working on fixing it, there's a woraround described in Jira - if possible use a unique attribute of the target object inside COUNT. E.g. a.shop.name (if no such attribute exists, map ID as an ObjAttribute, and use that).
>
> Andrus
>
>> On Oct 30, 2015, at 2:45 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>
>> Hi all, and a very happy Friday to you.
>>
>> How would I go about counting distinct related objects using EJBQL? If I want to count the number of “Shops" related to “Receipts", I’d expect to be able to do use EJBQL like this, which works fine for regular attributes:
>>
>> SELECT count(distinct a.shop) FROM Receipt a
>>
>> However, this generates the incorrect SQL
>>
>> SELECT COUNT(DISTINCT *) AS sc0 FROM smu.fd_receipt t0 INNER JOIN smu.fd_shop t1 ON (t0.shop_id = t1.id)
>>
>> Any ideas? I’m using the 4.0M3-SNAPSHOT release.
>>
>> Cheers,
>> - hugi
>