cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vital Zanko (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CAY-2521) Expression without Object ID disjoint issue
Date Tue, 05 Feb 2019 15:08:00 GMT
Vital Zanko created CAY-2521:
--------------------------------

             Summary: 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.1, 4.0
            Reporter: Vital Zanko
         Attachments: disjoint issue.png

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

{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:8]
[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 mydb2.team t1 ON (t0.id = t1.home_location_id)
WHERE t1.id = ? [bind: 1->id:8]
[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
= 8"));
// 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 mydb2.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