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] [Updated] (CAY-2521) Expression without Object ID disjoint issue
Date Fri, 01 Mar 2019 06:52:00 GMT

     [ https://issues.apache.org/jira/browse/CAY-2521?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Nikita Timofeev updated CAY-2521:
---------------------------------
    Fix Version/s:     (was: 4.1.M3)

> Expression without Object ID disjoint issue
> -------------------------------------------
>
>                 Key: CAY-2521
>                 URL: https://issues.apache.org/jira/browse/CAY-2521
>             Project: Cayenne
>          Issue Type: Bug
>    Affects Versions: 4.0, 4.0.1, 4.1.M3
>            Reporter: Vital Zanko
>            Assignee: Arseni Bulatski
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 4.0.2
>
>         Attachments: disjoint issue.png
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> As an example, there are three tables: issue, team, location. There are some relationships
among them:
>  * issue.home_team_id = team.id
>  * issue.location_id = location.id
>  * location.team_id = team.id
>  * team.home_location_id = location.id
> !disjoint issue.png!
> {code:java}
> Team team = Cayenne.objectForPK(localContext, Team.class, 1);
> 		
> SelectQuery<Issue> select = new SelectQuery<>(Issue.class, ExpressionFactory.exp("homeTeam
= 1"));
> select.addPrefetch(Issue.HOME_TEAM.disjoint());
> select.addPrefetch(Issue.LOCATION.disjoint());
> select.addPrefetch(Issue.HOME_TEAM.dot(Team.HOME_LOCATION).disjoint());
> List<Issue> issues = localContext.select(select);
> {code}
> This causes following sql query for prefetched team's home location objects which doesn't
correlate with the expression (it shouldn't be applied on): 
> {code:java}
> [05/Feb/2019:09:36:37,102] bootique-http-41 u=user1 INFO  o.a.c.l.JdbcEventLogger: SELECT
t0.name, t0.id, t0.team_id FROM mydb.location t0 WHERE t0.id = ? [bind: 1->id:1]
> [05/Feb/2019:09:36:37,104] bootique-http-41 u=user1 INFO  o.a.c.l.JdbcEventLogger: ===
returned 0 rows. - took 3 ms.
> {code}
>  
> The issue will be resolved when Object Id is being used as a parameter in the expression:
> {code:java}
> SelectQuery<Issue> select = new SelectQuery<>(Issue.class, ExpressionFactory.exp("homeTeam
= $id" , (Object) team.getObjectId()));
> // some custom code
> select.addPrefetch(Issue.HOME_TEAM.dot(Team.HOME_LOCATION).disjoint());
> List<Issue> issues = localContext.select(select);{code}
> {code:java}
> [05/Feb/2019:09:56:25,087] bootique-http-34 u=user1 INFO  o.a.c.l.JdbcEventLogger: SELECT
t0.name, t0.id, t0.team_id FROM mydb.location t0 JOIN mydb.team t1 ON (t0.id = t1.home_location_id)
WHERE t1.id = ? [bind: 1->id:1]
> [05/Feb/2019:09:56:25,100] bootique-http-34 u=user1 INFO  o.a.c.l.JdbcEventLogger: ===
returned 1 row. - took 13 ms.{code}
>  
> Or the issue will be also resolved in case of expression without object id when java
code declares _disjoint by id_
> {code:java}
> SelectQuery<Issue> select = new SelectQuery<>(Issue.class, ExpressionFactory.exp("homeTeam
= 1"));
> // some custom code
> select.addPrefetch(Issue.HOME_TEAM.dot(Team.HOME_LOCATION).disjointById());
> List<Issue> issues = localContext.select(select);
> {code}
> {code:java}
> [05/Feb/2019:09:59:23,605] bootique-http-36 u=user1 INFO  o.a.c.l.JdbcEventLogger: ---
transaction started.
> [05/Feb/2019:09:59:23,606] bootique-http-36 u=user1 INFO  o.a.c.l.JdbcEventLogger: SELECT
t0.name, t0.id, t0.team_id FROM mydb.location t0 WHERE t0.id = ? [bind: 1->id:71]
> [05/Feb/2019:09:59:23,609] bootique-http-36 u=user1 INFO  o.a.c.l.JdbcEventLogger: ===
returned 1 row. - took 4 ms.
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message