cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrey Razumovsky (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAY-1391) EJBQL unable to reference PKs not mapped as ObjAttributes
Date Tue, 06 Apr 2010 06:11:33 GMT

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

Andrey Razumovsky commented on CAY-1391:
----------------------------------------

EJBQL is still trying to fit JPA spec as possible, so I'm not sure this can be included in
3.0 release. For 3.1, we've been thinking about CayenneQL or something, which would include
some Cayenne-specific features, such as well-known "db:" prefix. 

> EJBQL unable to reference PKs not mapped as ObjAttributes
> ---------------------------------------------------------
>
>                 Key: CAY-1391
>                 URL: https://issues.apache.org/jira/browse/CAY-1391
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Core Library
>    Affects Versions: 3.0RC2
>            Reporter: Dave Lamy
>         Attachments: EJBQLPathTranslator.patch, EJBQLSelectTranslatorTest.patch
>
>
> I hit a case where an ObjEntity that contained an auto-generated PK needed to be referenced
by an EJBQL query.  The PK is not mapped as an ObjAttribute.
> The specific query case is when trying to perform a COUNT query with criteria on a to-many
association, such as:
> SELECT count(p) FROM Parent p JOIN p.children c WHERE c.age > 5
> The result in this case will be erroneous, as the generated SQL will count duplicated
parent IDs across the cartesian join on the children.
> The SQL fix for this is to include a DISTINCT in the count, but requesting a count(distinct
p) does not produce workable SQL.  Ideally then, one could reference the PK of the parent.
> I've written a solution to this using an HQL-esque "id" property to be referenced in
the select.  Thus this statement will work properly:
> SELECT count(distinct p.id) FROM Parent p JOIN p.children c WHERE c.age > 5
> The code will attempt to use the "normal" ObjAttribute discovery method first; but failing
that, if the last path component == "id" and the ObjEntity has a single PK then it will utilize
the PK ObjAttribute from the ObjEntity.  
> This code works on both my production test case as well as in the unit test.  Please
consider for inclusion in the next release, I hate monkey patches!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message