title: JPA - @EmbeddedId and @Id
body: <p>This is the relevant JPA code:</p>
  
  <pre><code>@MappedSuperClass
  public abstract class SuperClass {
  
    @EmbeddedId
    private FileId fileId;
  
    protected SuperClass() {
    }
  
    public SuperClass(FileId fileId) {
      this.fileId = fileId;
    }
  
  }
  
  @Embeddable
  public class FileId {
  
    protected FileId() {
    }
  
    protected File fileName;
  
    public FileId(File fileName) {
      this.fileName = fileName;
    }
  
  }
  
  @Entity
  public MyClass1 extends SuperClass {
  
    @Id
    protected String id;
  
    protected MyClass1() {
    }
  
    public MyClass1(String id, FileId fileId) {
      super(fileId);
      this.id = id;
    }
  
  }
  
  @Entity
  public MyClass2 extends SuperClass {
  
    protected MyClass2() {
    }
  
    public MyClass2(FileId fileId) {
      super(fileId);
    }
  
  }
  </code></pre>
  
  <p>At runtime I get the following exception:</p>
  
  <pre><code>...
  Exception Description: Entity class [class org.abcd.MyClass1] has both an @EmbdeddedId (on attribute [fileId]) and an @Id (on attribute [id]. Both ID types cannot be specified on the same entity.
  ...
  </code></pre>
  
  <p>It seems that defining a @EmbeddedId attribute (all attributes of the @Embeddable class) and a @Id attribute together as primary key is not allowed in JPA / Eclipse Link.</p>
  
  <p>Does anybody know a possible solution for this problem?</p>
  
  <p>Any help is appreciated.</p>
  
  <p><strong>Some additional information:</strong> </p>
  
  <p>The class MyClassA should contain information (progress, ...; ommited in the code example above) about a certain archive file; the attribute fileId of the super class SuperClass is used to identify this file. Currently fileId (the id-class FileId) only consists of the file name, but later more attributes will be added.</p>
  
  <p>MyClassB contains information about a file IN the archive. This file will be identified with the atttribute id (its the relative path in the archive) and fileId of the super class SuperClass.</p>
  
  <p>I think of the following database structure:</p>
  
  <p>Table "MyClass1":</p>
  
  <p>fileName | id | ...</p>
  
  <p>Table "MyClass2":</p>
  
  <p>fileName | ...</p>
  
  <p>I hope now it's a bit more clear what I exactly want :).</p>