title: jpa mapped superclass without id
body: <p>I'm curious about the following problem. I've two entites, <code>A</code> and <code>B</code>. It stores almost the same information (for example, a name - in real life it's more complex), but the joins, and the foreign keys differs.</p>
  
  <p>Can I do a mapped superclass, without an Id. And <code>class A</code> and <code>class B</code>, extending the mapped superclass, containing only the Id attribute?</p>
  
  <p>For example:</p>
  
  <pre><code>import lombok.Getter;
  import lombok.Setter;
  import lombok.Data;
  
  import javax.persistence.Entity;
  import javax.persistence.JoinColumn;
  import javax.persistence.MappedSuperclass;
  import javax.persistence.OneToMany;
  
  @MappedSuperclass
  @Getter
  @Setter
  @Data
  class superClass {
  
      @Column(name = "name")
      private String name;
  
  }
  
  @Entity
  @Table(name = "A")
  @Data
  class A extends superClass {
  
      @Id
      @OneToMany
      @JoinColumn(name = "id", referencedColumnName = "referencedName")
      private SomeClass id;
  
  }
  
  @Entity
  @Table(name = "B")
  @Data
  class B extends superClass {
  
      @Id
      @OneToOne
      @JoinColumn(name = "id", referencedColumnName = "referencedName")
      private SomeOtherClass id;
  
  }
  </code></pre>
  
  <p>Would it be valid by the JPA? I did read the <code>mappedSuperClass</code>'s JavaDocs, and says nothing about it. I would said, that it is valid - but the IntelliJ Idea says, that the super class has to have an Id attribute. I didn't find anything on the internet about this.</p>
  
  <p>edit: sorry, I missed it. I left the <code>Entity</code> annotation on the superClass, and that's why the Idea signed the error. I removed that, and the error disappeared. But I'm not sure, that this is valid, though.</p>