You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2019/12/17 15:28:32 UTC

[cayenne] branch STABLE-4.1 updated: CAY-2643 ObjectSelect.prefetch(name, semantics) method creates a phantom node

This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/STABLE-4.1 by this push:
     new f8975cf  CAY-2643 ObjectSelect.prefetch(name, semantics) method creates a phantom node
f8975cf is described below

commit f8975cf8eea3160e69113536b9673af642d033fb
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Tue Dec 17 18:23:12 2019 +0300

    CAY-2643 ObjectSelect.prefetch(name, semantics) method creates a phantom node
---
 RELEASE-NOTES.txt                                  |  9 ++++++++
 .../org/apache/cayenne/query/ObjectSelect.java     |  4 +++-
 .../cayenne/access/DataContextPrefetchIT.java      | 26 ++++++++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 3c8b4c9..6a090f9 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -8,6 +8,15 @@ To browse individual bug reports check out project issue tracker:
 https://issues.apache.org/jira/browse/CAY
 
 ----------------------------------
+Release: 4.1.RC3
+Date:
+----------------------------------
+
+Bug Fixes:
+
+CAY-2643 ObjectSelect.prefetch(name, semantics) method creates a phantom node
+
+----------------------------------
 Release: 4.1.RC2
 Date: October 25, 2019
 ----------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java b/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java
index f5e3c99..6d2487d 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java
@@ -398,7 +398,9 @@ public class ObjectSelect<T> extends FluentSelect<T> {
             prefetches = new PrefetchTreeNode();
         }
 
-        prefetches.addPath(path).setSemantics(semantics);
+        PrefetchTreeNode prefetchTreeNode = prefetches.addPath(path);
+        prefetchTreeNode.setSemantics(semantics);
+        prefetchTreeNode.setPhantom(false);
         replacementQuery = null;
         return this;
     }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchIT.java
index c52f322..d2b7913 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchIT.java
@@ -30,6 +30,7 @@ import org.apache.cayenne.exp.Property;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.query.ObjectSelect;
+import org.apache.cayenne.query.PrefetchTreeNode;
 import org.apache.cayenne.query.QueryCacheStrategy;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.test.jdbc.DBHelper;
@@ -239,6 +240,31 @@ public class DataContextPrefetchIT extends ServerCase {
 		});
 	}
 
+	@Test
+	public void testPrefetchByPathToManyNoQualifier() throws Exception {
+		createTwoArtistsAndTwoPaintingsDataSet();
+
+		List<Artist> artists = ObjectSelect.query(Artist.class)
+				.prefetch("paintingArray", PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS)
+				.select(context);
+
+		queryInterceptor.runWithQueriesBlocked(() -> {
+
+			assertEquals(2, artists.size());
+
+			for (int i = 0; i < 2; i++) {
+				Artist a = artists.get(i);
+				List<?> toMany = (List<?>) a.readPropertyDirectly("paintingArray");
+				assertNotNull(toMany);
+				assertFalse(((ValueHolder) toMany).isFault());
+				assertEquals(1, toMany.size());
+
+				Painting p = (Painting) toMany.get(0);
+				assertEquals("Invalid prefetched painting:" + p, "p_" + a.getArtistName(), p.getPaintingTitle());
+			}
+		});
+	}
+
 	/**
 	 * Test that a to-many relationship is initialized when a target entity has
 	 * a compound PK only partially involved in relationship.