title: Creating JPA entity with composite primary key with @Id from @MappedSuperclass
body: <p>I have a class hierarchy for JPA entities with the base class being a MappedSuperclass which has one ID defined. I am trying to use a composite key in a subclass however that does not seem to work</p>
  
  <p>My code looks like this</p>
  
  <pre><code>@MappedSuperclass
  public class BaseEntity implements Serializable {
      @Id  
      @GeneratedValue(strategy = GenerationType.IDENTITY)  
      @Basic(optional = false)  
      @Column(name = "id")  
      protected Long id;  
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  }
  
  
  @Entity
  @EntityListeners(EntityBaseListener.class)
  @Inheritance(strategy=InheritanceType.JOINED)  
  @Table(name = "catalog_entity")  
  public class BaseCatalogEntity extends BaseEntity {
  
      @Column(name = "created_at", nullable = false)
      @Temporal(TemporalType.TIMESTAMP)
      private Date createdAt;
  
      @Column(name = "updated_at", nullable = false)
      @Temporal(TemporalType.TIMESTAMP)
      private Date updatedAt;
  
  
      public void setCreatedAt(Date date)
      {
          createdAt = date;
      }
  
      public void setUpdatedAt(Date date)
      {
          updatedAt = date;
      }
  
      public Date getCreatedAt() {
          return createdAt;
      }
  
      public Date getUpdatedAt() {
          return updatedAt;
      }
  
  }
  
  
  @Entity
  @Table(schema = "student_catalog")
  @IdClass(value = StudentCatalog.StudentCatalogPK.class)
  public class StudentCatalog extends BaseCatalogEntity {
  
      @Id
      @Column(name = "name", nullable = false, length = 100)
      private String name;
  
      @Id
      @Column(name = "version", nullable = false)
      private Integer version;
  
      @Column(name = "description" , length = 255)
      private String description; 
  
      @Column(name = "vendor" , length = 50)
      private String vendor; 
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Integer getVersion() {
          return version;
      }
  
      public void setVersion(Integer version) {
          this.version = version;
      }
  
      public String getDescription() {
          return description;
      }
  
      public void setDescription(String description) {
          this.description = description;
      }
  
      public String getVendor() {
          return vendor;
      }
  
      public void setVendor(String vendor) {
          this.vendor = vendor;
      }
  
      public static class StudentCatalogPK implements Serializable {
  
          private Long id;
          private String name;
          private Integer version;
  
          public Long getId() {
              return id;
          }
  
          public void setId(Long id) {
              this.id = id;
          }
  
          public String getName() {
              return name;
          }
  
          public void setName(String name) {
              this.name = name;
          }
  
          public Integer getVersion() {
              return version;
          }
  
          public void setVersion(Integer version) {
              this.version = version;
          }
  
          @Override
          public boolean equals(Object obj) {
              boolean result = false;
              if(obj != null &amp;&amp; (obj instanceof StudentCatalogPK)) {
                  StudentCatalogPK other = (StudentCatalogPK)obj;
                  result = (Objects.equals(this.id, other.id) &amp;&amp; Objects.equals(this.name, other.name) &amp;&amp;
                          Objects.equals(this.version, other.version));
              }
              return result;
          }
  
          @Override
          public int hashCode() {
              return (27780 + (this.id != null ? this.id.hashCode() : 0) +
                             (this.version != null ? this.version.hashCode() : 0) +
                             (this.name != null ? this.name.hashCode() : 0));
          }
      }
  }
  </code></pre>
  
  <p>I get the following exception:</p>
  
  <p>Exception Description: Invalid composite primary key specification. The names of the primary key fields or properties in the primary key class [com.example.jpa.StudentCatalog$StudentCatalogPK] and those of the entity bean class [class com.example.jpa.StudentCatalog] must correspond and their types must be the same. Also, ensure that you have specified ID elements for the corresponding attributes in XML and/or an @Id on the corresponding fields or properties of the entity class.</p>
  
  <p>I am using Eclipselink 2.5.1. Is there a way I can get this to work without changing the BaseEntity and BaseCatalogEntity classes?</p>