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

commit 109d6c365e794d14f73d23ed6e97ea53e86131e7
Author: Nikita Timofeev <[email protected]>
AuthorDate: Mon Oct 7 17:59:51 2019 +0300

    CAY-2628 dbimport: unable to add several relationships to existing entity
    
    (cherry picked from commit 9a6ab370ab8dfe11c94723c79b05c6bd6ab35bb7)
---
 RELEASE-NOTES.txt                                  |  1 +
 .../dbsync/merge/DbRelationshipDictionary.java     |  4 +-
 .../testImportNewRelationship.map.xml-result       | 58 ++++++++++++++--------
 .../tools/dbimport/testImportNewRelationship.sql   | 10 +++-
 4 files changed, 49 insertions(+), 24 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index dc73327..5433ae9 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -44,6 +44,7 @@ CAY-2618 Unstable property ordering in generated classes
 CAY-2619 "to-dep PK" related dbimport delta confuses the Modeler
 CAY-2624 SelectQuery "having" qualifier is not considered when calculating 
cache key
 CAY-2627 Modeler: ObjRelationship creation dialog ignores delete rule
+CAY-2628 dbimport: unable to add several relationships to existing entity
 
 ----------------------------------
 Release: 4.1.B2
diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java
 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java
index ae014d2..df66d03 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java
@@ -100,9 +100,9 @@ class DbRelationshipDictionary extends 
MergerDictionary<DbRelationship> {
             TreeSet<String> joins = new TreeSet<>();
             for(DbJoin join : relationship.getJoins()) {
                 joins.add(
-                        (join.getSource() == null ? "~" : 
join.getSource().getName()) + "." + join.getSourceName()
+                        relationship.getSourceEntityName() + "." + 
join.getSourceName()
                         + ">" +
-                        (join.getTarget() == null ? "~" : 
join.getTarget().getName()) + "." + join.getTargetName()
+                        relationship.getTargetEntityName() + "." + 
join.getTargetName()
                 );
             }
             joinSignature = joins.toArray(new String[0]);
diff --git 
a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
 
b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
index 23e2f6f..240054c 100644
--- 
a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
+++ 
b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
@@ -18,31 +18,47 @@
   ~  under the License.
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
 <data-map xmlns="http://cayenne.apache.org/schema/10/modelMap";
-        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-        xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap 
http://cayenne.apache.org/schema/10/modelMap.xsd";
-        project-version="10">
-        <property name="defaultSchema" value="SCHEMA_01"/>
-        <db-entity name="TABLE1" schema="SCHEMA_01">
-               <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" 
isMandatory="true" length="10"/>
-               <db-attribute name="T1_NAME" type="VARCHAR" length="45"/>
-     </db-entity>
-     <db-entity name="TABLE2" schema="SCHEMA_01">
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+          xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap 
http://cayenne.apache.org/schema/10/modelMap.xsd";
+          project-version="10">
+    <property name="defaultSchema" value="SCHEMA_01"/>
+    <db-entity name="TABLE1" schema="SCHEMA_01">
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" 
isMandatory="true" length="10"/>
+        <db-attribute name="T1_NAME" type="VARCHAR" length="45"/>
+    </db-entity>
+    <db-entity name="TABLE2" schema="SCHEMA_01">
         <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" 
isMandatory="true" length="10"/>
         <db-attribute name="T2_NAME" type="VARCHAR" length="45"/>
         <db-attribute name="TABLE1_ID" type="INTEGER" isMandatory="true" 
length="10"/>
-     </db-entity>
-     <obj-entity name="Table1" className="Table1" dbEntityName="TABLE1">
-         <obj-attribute name="t1Name" type="java.lang.String" 
db-attribute-path="T1_NAME"/>
-     </obj-entity>
-     <obj-entity name="Table2" className="Table2" dbEntityName="TABLE2">
+    </db-entity>
+    <db-entity name="TABLE3" schema="SCHEMA_01">
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" 
isMandatory="true" length="10"/>
+        <db-attribute name="T3_NAME" type="VARCHAR" length="45"/>
+        <db-attribute name="TABLE1_ID" type="INTEGER" isMandatory="true" 
length="10"/>
+    </db-entity>
+    <obj-entity name="Table1" className="Table1" dbEntityName="TABLE1">
+        <obj-attribute name="t1Name" type="java.lang.String" 
db-attribute-path="T1_NAME"/>
+    </obj-entity>
+    <obj-entity name="Table2" className="Table2" dbEntityName="TABLE2">
         <obj-attribute name="t2Name" type="java.lang.String" 
db-attribute-path="T2_NAME"/>
-     </obj-entity>
-     <db-relationship name="table2s" source="TABLE1" target="TABLE2" 
toMany="true">
+    </obj-entity>
+    <obj-entity name="Table3" className="Table3" dbEntityName="TABLE3">
+        <obj-attribute name="t3Name" type="java.lang.String" 
db-attribute-path="T3_NAME"/>
+    </obj-entity>
+    <db-relationship name="table3s" source="TABLE1" target="TABLE3" 
toMany="true">
         <db-attribute-pair source="ID" target="TABLE1_ID"/>
-     </db-relationship>
-     <db-relationship name="table1" source="TABLE2" target="TABLE1">
+    </db-relationship>
+    <db-relationship name="table2s" source="TABLE1" target="TABLE2" 
toMany="true">
+        <db-attribute-pair source="ID" target="TABLE1_ID"/>
+    </db-relationship>
+    <db-relationship name="table1" source="TABLE2" target="TABLE1">
+        <db-attribute-pair source="TABLE1_ID" target="ID"/>
+    </db-relationship>
+    <db-relationship name="table1" source="TABLE3" target="TABLE1">
         <db-attribute-pair source="TABLE1_ID" target="ID"/>
-     </db-relationship>
-     <obj-relationship name="table2s" source="Table1" target="Table2" 
deleteRule="Deny" db-relationship-path="table2s"/>
-     <obj-relationship name="table1" source="Table2" target="Table1" 
deleteRule="Nullify" db-relationship-path="table1"/>
+    </db-relationship>
+    <obj-relationship name="table3s" source="Table1" target="Table3" 
deleteRule="Deny" db-relationship-path="table3s"/>
+    <obj-relationship name="table2s" source="Table1" target="Table2" 
deleteRule="Deny" db-relationship-path="table2s"/>
+    <obj-relationship name="table1" source="Table2" target="Table1" 
deleteRule="Nullify" db-relationship-path="table1"/>
+    <obj-relationship name="table1" source="Table3" target="Table1" 
deleteRule="Nullify" db-relationship-path="table1"/>
 </data-map>
\ No newline at end of file
diff --git 
a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
 
b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
index 81115f9..7c667e5 100644
--- 
a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
+++ 
b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
@@ -29,5 +29,13 @@ CREATE TABLE schema_01.table2 (
     t2_name VARCHAR (45),
     table1_id INTEGER  NOT NULL,
     PRIMARY KEY (id),
-    CONSTRAINT fk_address FOREIGN KEY (table1_id) REFERENCES schema_01.table1 
(id)
+    CONSTRAINT fk_table2_table1_id FOREIGN KEY (table1_id) REFERENCES 
schema_01.table1 (id)
+);
+
+CREATE TABLE schema_01.table3 (
+    id INTEGER  NOT NULL,
+    t3_name VARCHAR (45),
+    table1_id INTEGER  NOT NULL,
+    PRIMARY KEY (id),
+    CONSTRAINT fk_table3_table1_id FOREIGN KEY (table1_id) REFERENCES 
schema_01.table1 (id)
 );
\ No newline at end of file

Reply via email to