OPENJPA-2705: ArrayOutOfBoundsException occurs with an @EmbeddedId (commit on wdazeys behalf)

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1802421 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
index fcecda2..c5768fa 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
@@ -269,7 +269,7 @@
                 // If on the other hand we are dealing with an embeddable that is an @IdClass, fms.size will be the 
                 // number columns in the @IdClass.  Furthermore, when dealing with @IdClass, 'ret' will already  
                 // properly contain the column values, therefore no further processing is needed.
-                if (fmsPK[0].isEmbedded() && cols.length > 1 && fms.size() == 1) {
+                if (fmsPK.length > 0 && fmsPK[0].isEmbedded() && cols.length > 1 && fms.size() == 1) {
                     // OK, we know this PK is an embeddable. So get the individual field values.
                     Object[] tmpRet = new Object[cols.length];
                     for (int i = 0; i < cols.length; i++) {
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/compositepk/TestCompositePrimaryKeys.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/compositepk/TestCompositePrimaryKeys.java
index d6e7e7b..416d7e8 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/compositepk/TestCompositePrimaryKeys.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/compositepk/TestCompositePrimaryKeys.java
@@ -19,10 +19,12 @@
 package org.apache.openjpa.persistence.embed.compositepk;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
 import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
@@ -111,7 +113,7 @@
      * 
      * ArgumentException: An error occurred while parsing the query filter 'select distinct g from Topic g where
      * t.subject.key = :subjectKey'. Error message: JPQL query does not support conditional expression over embeddable
-     * class. JPQL string: "key".
+     * class. JPQL string: "key". See section 4.6.3 of the JPA 2.0 specification.
      * 
      * The message in the exception tells it all. Per the spec, you can not do a compare on embeddables.
      */
@@ -188,6 +190,23 @@
     }
 
     /*
+     * Due to the fix #1 (see notes above), this fails on OJ with:
+     * 
+     * java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
+     * at org.apache.openjpa.jdbc.meta.ClassMapping.toDataStoreValue(ClassMapping.java:272)
+     * 
+     */
+    public void testFindUsingJPQLSubjectKeyIn() { 
+        Query query = em.createQuery("select distinct s from Subject s where s.key in :subjectKeyList");
+        query.setParameter("subjectKeyList", 
+                Arrays.asList(
+                    new SubjectKey(1, "Type"), 
+                    new SubjectKey(2, "Type2"), 
+                    new SubjectKey(3, "Type3")));
+        query.getResultList();
+    }
+
+    /*
      * Prior to the fix #1 (see notes above), this fails on OJ with:
      * 
      * java.lang.ClassCastException: org.apache.openjpa.persistence.embed.compositepk.SubjectKey cannot be cast to