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


The following commit(s) were added to refs/heads/master by this push:
     new efcba9b  CAY-2578 Wrong bindings in select of related entity by 
compound FK   fix tests
efcba9b is described below

commit efcba9bb11e53ba1b608dd11bee33b77fec3e3a0
Author: Nikita Timofeev <[email protected]>
AuthorDate: Sat May 11 16:48:18 2019 +0300

    CAY-2578 Wrong bindings in select of related entity by compound FK
      fix tests
---
 .../src/main/java/org/apache/cayenne/dba/JdbcAdapter.java      | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java 
b/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
index 8da76e0..2ad9d06 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
@@ -55,6 +55,7 @@ import java.sql.PreparedStatement;
 import java.sql.Types;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.function.Function;
@@ -456,7 +457,14 @@ public class JdbcAdapter implements DbAdapter {
 
         boolean first = true;
 
-        for (DbJoin join : rel.getJoins()) {
+        // sort joins in the order PK are set in target, to avoid errors on 
some DBs
+        List<DbJoin> joins = rel.getJoins();
+        if(rel.isToPK()) {
+            List<DbAttribute> pks = rel.getTargetEntity().getPrimaryKeys();
+            joins.sort(Comparator.comparingInt(join -> 
pks.indexOf(join.getTarget())));
+        }
+
+        for (DbJoin join : joins) {
             if (first) {
                 first = false;
             } else {

Reply via email to