cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikita Timofeev (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CAY-2356) EJBQL: Incorrect COUNT() on outer joined table
Date Wed, 30 Aug 2017 15:02:01 GMT

    [ https://issues.apache.org/jira/browse/CAY-2356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16147375#comment-16147375
] 

Nikita Timofeev edited comment on CAY-2356 at 8/30/17 3:01 PM:
---------------------------------------------------------------

Fixed in *4.1* per https://github.com/apache/cayenne/commit/e44f2fab57b4958c805e024dc65b1f11b63df6a5
Fixed in *4.0* per https://github.com/apache/cayenne/commit/77fc8b79d1f8055cec8d768e46188450c91bf667

Solution is to use COUNT(nonNullPK) instead of COUNT(*).
Plus this fix allows COUNT(1) usage.


was (Author: ntimofeev):
Fixed in *4.1* per https://github.com/apache/cayenne/commit/e44f2fab57b4958c805e024dc65b1f11b63df6a5

Solution is to use COUNT(nonNullPK) instead of COUNT(*).
Plus this fix allows COUNT(1) usage.

> EJBQL: Incorrect COUNT() on outer joined table 
> -----------------------------------------------
>
>                 Key: CAY-2356
>                 URL: https://issues.apache.org/jira/browse/CAY-2356
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 4.0.B1, 4.1.M1
>            Reporter: Nikita Timofeev
>            Priority: Minor
>             Fix For: 4.0.B1, 4.1.M1
>
>
> This query:
> {code}
> EJBQLQuery asc = new EJBQLQuery("select a, count(p) from Artist a LEFT JOIN a.paintingArray
p GROUP BY a order by count(p) DESC");
> {code}
> Produces following SQL:
> {code:sql}
> SELECT
>     t0.ARTIST_NAME AS ec0_0, 
>     t0.DATE_OF_BIRTH AS ec0_1,
>     t0.ARTIST_ID AS ec0_2, 
>     COUNT(*) AS sc1
> FROM
>     ARTIST t0
>     LEFT OUTER JOIN PAINTING t1 ON (t0.ARTIST_ID = t1.ARTIST_ID)
> GROUP BY t0.ARTIST_NAME, t0.DATE_OF_BIRTH, t0.ARTIST_ID
> ORDER BY COUNT(*)
> {code}
> Note *{{COUNT( * )}}* that gives unexpected result, if there are no paintings it will
return *1* instead of *0*, {{COUNT(t1.PAINTING_ID)}} should be used instead.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message