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 2020/10/01 08:56:01 UTC

[cayenne] 01/02: CAY-2679 Unstable ordering of relationships in the .map.xml file

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

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

commit 127f9ec08ec91a7261a99dda2d5ba5f7dbddc361
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Wed Sep 30 18:20:47 2020 +0300

    CAY-2679 Unstable ordering of relationships in the .map.xml file
---
 RELEASE-NOTES.txt                                                | 1 +
 cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index d38d9fc..e8b706b 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -31,6 +31,7 @@ Bug Fixes:
 CAY-2591 Modeler: project becomes dirty after click on dbImport or cgen tab
 CAY-2671 QualifierTranslator fails to translate expressions with compound PKs/FKs
 CAY-2675 A one-to-one relationship with meaningful PK can be nullified in the nested context
+CAY-2679 Unstable ordering of relationships in the .map.xml file
 
 ----------------------------------
 Release: 4.2.M1
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java b/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
index 9bebad8..7ea1521 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
@@ -37,6 +37,7 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
@@ -335,7 +336,9 @@ public class DataMap implements Serializable, ConfigurationNode, XMLSerializable
 	// stores relationships for the map of entities
 	private void encodeDbRelationshipsAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate) {
 		for (Entity entity : new TreeMap<>(getDbEntityMap()).values()) {
-			entity.getRelationships().stream().filter(r -> !r.isRuntime())
+			entity.getRelationships().stream()
+					.filter(r -> !r.isRuntime())
+					.sorted(Comparator.comparing(Relationship::getName))
 					.forEach(r -> r.encodeAsXML(encoder, delegate));
 		}
 	}
@@ -343,7 +346,9 @@ public class DataMap implements Serializable, ConfigurationNode, XMLSerializable
 	// stores relationships for the map of entities
 	private void encodeObjRelationshipsAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate) {
 		for (ObjEntity entity : new TreeMap<>(getObjEntityMap()).values()) {
-			entity.getDeclaredRelationships().stream().filter(r -> !r.isRuntime())
+			entity.getDeclaredRelationships().stream()
+					.filter(r -> !r.isRuntime())
+					.sorted(Comparator.comparing(Relationship::getName))
 					.forEach(r -> r.encodeAsXML(encoder, delegate));
 		}
 	}