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
This commit is contained in:
Jody Grassel 2017-07-19 18:18:13 +00:00
parent dddfed9f4c
commit 1c8b15fc38
2 changed files with 21 additions and 2 deletions

View File

@ -269,7 +269,7 @@ public class ClassMapping
// 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++) {

View File

@ -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 @@ public class TestCompositePrimaryKeys extends SingleEMFTestCase {
*
* 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.
*/
@ -187,6 +189,23 @@ public class TestCompositePrimaryKeys extends SingleEMFTestCase {
verifyResults(topic, s);
}
/*
* 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:
*