531528: IdentifiableType.hasSingleIdAttribute() returns true when IdClass references an inner class

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
Reviewed-by: TomasK
diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/WithInner.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/WithInner.java
new file mode 100644
index 0000000..6d75f1f
--- /dev/null
+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/WithInner.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *     02/26/2018-2.7.2 Lukas Jungmann
+ *       - 531528: IdentifiableType.hasSingleIdAttribute() returns true when IdClass references an inner class
+ ******************************************************************************/
+package org.eclipse.persistence.testing.models.jpa.metamodel;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="INNER_PK")
+@IdClass(WithInner.InnerPK.class)
+public class WithInner {
+
+    @Column(name="DESC")
+    public String description;
+
+    @Id
+    @Column(name="ID1")
+    public int id1;
+
+    @Id
+    @Column(name="ID2")
+    public String id2;
+
+    public static class InnerPK implements Serializable {
+
+        private int id1;
+        private String id2;
+
+        public int getId1() {
+            return id1;
+        }
+
+        public void setId1(int id1) {
+            this.id1 = id1;
+        }
+
+        public String getId2() {
+            return id2;
+        }
+
+        public void setId2(String id2) {
+            this.id2 = id2;
+        }
+    }
+}
diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java
index b5aba0d..4232939 100644
--- a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java
+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
  * which accompanies this distribution.
@@ -95,7 +95,7 @@
 import org.eclipse.persistence.testing.models.jpa.metamodel.Position;
 import org.eclipse.persistence.testing.models.jpa.metamodel.Processor;
 import org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor;
-
+import org.eclipse.persistence.testing.models.jpa.metamodel.WithInner;
 import org.eclipse.persistence.testing.framework.junit.JUnitTestCase;
 
 /**
@@ -123,9 +123,9 @@
  */
 public class MetamodelMetamodelTest extends MetamodelTest {
 
-    public static final int METAMODEL_ALL_ATTRIBUTES_SIZE = 147;//6;
+    public static final int METAMODEL_ALL_ATTRIBUTES_SIZE = 150;//6;
     // Note: Since BasicTypes are lazy - loaded into the metamodel-types Map - this test must preceed any test that verifies all BasicType objects like "testIdentifiableType_getIdType_Method"
-    public static final int METAMODEL_ALL_TYPES = 51;
+    public static final int METAMODEL_ALL_TYPES = 52;
     public static final int METAMODEL_MANUFACTURER_DECLARED_TYPES = 28;
     // Get # of processor cores (hard cores + hyperthreaded cores)
     public static final int numberProcessingUnits = Runtime.getRuntime().availableProcessors();
@@ -2000,6 +2000,8 @@
             assertNotNull(entityLocation_);
             EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
             assertNotNull(entityComputer_);
+            EntityTypeImpl<WithInner> withInner_ = (EntityTypeImpl)metamodel.entity(WithInner.class);
+            assertNotNull(withInner_);
 
             /**
              *  Whether or not the identifiable type has an id attribute.
@@ -2049,6 +2051,19 @@
             }
             assertFalse(expectedIAExceptionThrown);
             assertFalse(hasSingleIdAttribute);
+
+            // @IdClass - inner
+            expectedIAExceptionThrown = false;
+            hasSingleIdAttribute = false;
+        try {
+            EntityType<WithInner> aType = metamodel.entity(WithInner.class);
+            hasSingleIdAttribute = aType.hasSingleIdAttribute();
+        } catch (IllegalArgumentException iae) {
+            iae.printStackTrace();
+            expectedIAExceptionThrown = true;
+            }
+            assertFalse(expectedIAExceptionThrown);
+            assertFalse(hasSingleIdAttribute);
         } catch (IllegalArgumentException iae) {
             iae.printStackTrace();
             expectedIAExceptionThrown = true;
diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTableCreator.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTableCreator.java
index 2828c2d..e9aada1 100644
--- a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTableCreator.java
+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTableCreator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
  * which accompanies this distribution.
@@ -73,6 +73,8 @@
         addTableDefinition(buildGALACTICPOSITIONTable());
         // Test ms-ms-entity chain with idclass above id
         addTableDefinition(buildMS_MS_Entity_Leaf_Table());
+        // Test idclass in inner class
+        addTableDefinition(buildWITHINNERPKTable());
 
 
         // 1:n
@@ -1110,6 +1112,43 @@
         return table;
     }
 
+    public static TableDefinition buildWITHINNERPKTable() {
+        TableDefinition table = new TableDefinition();
+        table.setName("INNER_PK");
+
+        FieldDefinition field = new FieldDefinition();
+        field.setName("DESC");
+        field.setTypeName("VARCHAR");
+        field.setSize(80);
+        field.setShouldAllowNull(false);
+        field.setIsPrimaryKey(false);
+        field.setUnique(false);
+        field.setIsIdentity(true);
+        table.addField(field);
+
+        FieldDefinition field4 = new FieldDefinition();
+        field4.setName("ID1");
+        field4.setTypeName("NUMERIC");
+        field4.setSize(15);
+        field4.setShouldAllowNull(true);
+        field4.setIsPrimaryKey(true);
+        field4.setUnique(true);
+        field4.setIsIdentity(false);
+        table.addField(field4);
+
+        FieldDefinition field6 = new FieldDefinition();
+        field6.setName("ID2");
+        field6.setTypeName("VARCHAR");
+        field6.setSize(15);
+        field6.setShouldAllowNull(false);
+        field6.setIsPrimaryKey(true);
+        field6.setUnique(true);
+        field6.setIsIdentity(false);
+        table.addField(field6);
+
+        return table;
+    }
+
     public static TableDefinition buildGALACTICPOSITIONTable() {
         TableDefinition table = new TableDefinition();
         table.setName("CMP3_MM_GALACTIC");
diff --git a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/MappedSuperclassAccessor.java b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/MappedSuperclassAccessor.java
index fe545e8..e5b7782 100644
--- a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/MappedSuperclassAccessor.java
+++ b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/MappedSuperclassAccessor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 1998, 2017 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
  * which accompanies this distribution.
@@ -74,6 +74,8 @@
  *       - 395406: Fix nightly static weave test errors
  *     06/12/2017-2.7 Lukas Jungmann
  *       - 518155: [jpa22] add support for repeatable annotations
+ *     02/26/2018-2.7.2 Lukas Jungmann
+ *       - 531528: IdentifiableType.hasSingleIdAttribute() returns true when IdClass references an inner class
  ******************************************************************************/
 package org.eclipse.persistence.internal.jpa.metadata.accessors.classes;
 
@@ -620,7 +622,7 @@
         if (m_idClass != null && ! m_idClass.equals(void.class)) {
             getProject().addIdClass(m_idClass.getName());
             // 266912: We store the IdClass (not an EmbeddableId) for use by the Metamodel API
-            getProject().getProject().addMetamodelIdClassMapEntry(getAccessibleObject().getName(), m_idClass.getName());
+            getProject().getProject().addMetamodelIdClassMapEntry(getAccessibleObject().getName(), m_idClass.getName().replace('$', '.'));
         }
     }