1

I want to create a primary composite key and use an @Id field from a parent class. But it does not work. Why?

@MappedSuperclass
static abstract class SuperEntity {
    @Id
    private Long id;
}

@Entity
@IdClass(SuperPK.class)
public static class ChildEntity extends SuperEntity {
    @Id
    private String lang;
}


public class SuperPK {
    public SuperPK(Long id, String lang) {
        //...
    }
}

Result: Property of @IdClass not found in entity ChildEntity: id

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • 1
    Possible duplicate of [Composite Key in JPA / Hibernate with inherited class](http://stackoverflow.com/questions/4216102/composite-key-in-jpa-hibernate-with-inherited-class) – Tobias Liefke Dec 08 '15 at 15:38

1 Answers1

1

I found an open issue regarding this bug.

One of the comments states to override the getters for the ID properties as a workaround.

@Entity
@IdClass(SuperPK.class)
public static class ChildEntity extends SuperEntity {
    @Id
    private String lang;

    @Override @Id
    public Long getId() {
        return super.getId();
    }
}
Peba
  • 440
  • 4
  • 14