cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Kienenberger (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAY-1875) PrefetchSelectQuery incorrectly applies entity qualifiers
Date Thu, 26 Sep 2013 21:18:06 GMT

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

Mike Kienenberger commented on CAY-1875:
----------------------------------------

The above patch isn't correct.   The problem isn't the translation of the entity, it's the
wrong entity qualifier entirely.   I think the problem is that, in addition to the entity
qualifiers above, the prefetch entity qualifier also needs to be appended.   I'm not sure
if this is the most efficient way to create the missing qualifier, nor if the translateToRelatedEntity
method needs to be called on the missing qualifier (I didn't call it), but the tests all pass
with this change.   Unfortunately, this is adding my qualifiers twice.   I can live with that
in the short term, since having the same qualifier added twice is better than not at all,
but this probably means there is another problem here that I am not seeing.   For prefetch
entities with no qualifier, everything looks fine.

SELECT DISTINCT t0.[...] FROM SCHEDULED_PAYMENT t0 JOIN ACCOUNT t1 ON (t0.ACCOUNT_NUMBER =
t1.ACCOUNT_NUMBER) JOIN USER_ACCOUNT_RELATIONSHIP t2 ON (t1.ACCOUNT_NUMBER = t2.ACCOUNT_NUMBER)
WHERE (t2.USER_ID = ?) AND (t2.INVALIDATED = ?) AND (t0.INVALIDATED = ?) AND (t0.INVALIDATED
= ?) [bind: 1:56, 2:'N', 3:'N', 4:'N']


Index: framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryPrefetchRouterAction.java
===================================================================
--- framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryPrefetchRouterAction.java
(revision 1524993)
+++ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryPrefetchRouterAction.java
(working copy)
@@ -23,6 +23,7 @@
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.map.EntityInheritanceTree;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.reflect.ClassDescriptor;
@@ -95,15 +96,25 @@
                     .andExp(entityQualifier) : entityQualifier;
         }
 
+        Expression translatedToRelatedEntityExpression = classDescriptor.getEntity().translateToRelatedEntity(
+                queryQualifier,
+                prefetchPath);
+
+        EntityInheritanceTree prefetchEntityInheritanceTree = resolver.lookupInheritanceTree(relationship.getTargetEntity().getName());

+        Expression prefetchEntityQualifier = prefetchEntityInheritanceTree.qualifierForEntityAndSubclasses();
+
+        if (prefetchEntityQualifier != null) {
+        	translatedToRelatedEntityExpression = (translatedToRelatedEntityExpression != null)
? translatedToRelatedEntityExpression
+                    .andExp(prefetchEntityQualifier) : prefetchEntityQualifier;
+        }
+
         // create and configure PrefetchSelectQuery
         PrefetchSelectQuery prefetchQuery = new PrefetchSelectQuery(
                 prefetchPath,
                 relationship);
         prefetchQuery.setStatementFetchSize(query.getStatementFetchSize());
 
-        prefetchQuery.setQualifier(classDescriptor.getEntity().translateToRelatedEntity(
-                queryQualifier,
-                prefetchPath));
+		prefetchQuery.setQualifier(translatedToRelatedEntityExpression);
 
         if (relationship.isSourceIndependentFromTargetChange()) {
             // setup extra result columns to be able to relate result rows to the parent

                
> PrefetchSelectQuery incorrectly applies entity qualifiers
> ---------------------------------------------------------
>
>                 Key: CAY-1875
>                 URL: https://issues.apache.org/jira/browse/CAY-1875
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.1B2
>            Reporter: Mike Kienenberger
>
> The modeler's entity qualifier isn't applied to prefetch queries.
> http://www.mail-archive.com/user@cayenne.apache.org/msg08241.html
> Andrus:
> > This is bad and is not supposed to happen. Appears to be a bug. I am checking
> > SelectQueryPrefetchRouterAction, and it applies *root* entity qualifier to prefetch
query instead of
> > prefetched entity. Should be a relatively easy fix for "disjoint" prefetches at
least.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message