You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2012/11/01 22:47:48 UTC

svn commit: r1404780 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java

Author: aadamchik
Date: Thu Nov  1 21:47:47 2012
New Revision: 1404780

URL: http://svn.apache.org/viewvc?rev=1404780&view=rev
Log:
CAY-1751 FK pointing to an UNIQUE field. Problems to insert registers

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java?rev=1404780&r1=1404779&r2=1404780&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java Thu Nov  1 21:47:47 2012
@@ -40,6 +40,7 @@ import org.apache.cayenne.QueryResponse;
 import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.cache.QueryCacheEntryFactory;
 import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.LifecycleEvent;
 import org.apache.cayenne.map.ObjRelationship;
@@ -194,11 +195,23 @@ class DataDomainQueryAction implements Q
             ObjRelationship relationship = relationshipQuery.getRelationship(domain
                     .getEntityResolver());
 
-            // check if we can derive target PK from FK... this implies that the
-            // relationship is to-one
+            // check if we can derive target PK from FK...
             if (relationship.isSourceIndependentFromTargetChange()) {
                 return !DONE;
             }
+            
+            // we can assume that there is one and only one DbRelationship as
+            // we previously checked that "!isSourceIndependentFromTargetChange"
+            DbRelationship dbRelationship = relationship.getDbRelationships().get(0);
+            
+            // FK pointing to a unique field that is a 'fake' PK (CAY-1751)...
+            // It is not sufficient to generate target ObjectId.
+            DbEntity targetEntity = (DbEntity) dbRelationship.getTargetEntity();
+            if (dbRelationship.getJoins().size() < targetEntity
+                    .getPrimaryKeys().size()) {
+                return !DONE;
+            }
+            
 
             if (cache == null) {
                 return !DONE;
@@ -209,9 +222,6 @@ class DataDomainQueryAction implements Q
                 return !DONE;
             }
 
-            // we can assume that there is one and only one DbRelationship as
-            // we previously checked that "!isSourceIndependentFromTargetChange"
-            DbRelationship dbRelationship = relationship.getDbRelationships().get(0);
 
             ObjectId targetId = sourceRow.createTargetObjectId(
                     relationship.getTargetEntityName(),