JPA @MappedSuperclass 没有为实体指定标识符

JPA @MappedSuperclass No identifier specified for entity

我正在使用 Spring-Boot 1.5.10 和 spring-boot-starter-data-jpa。我有一个 staging table 和一个 production table,两者具有相同的结构,只是名称不同 table。列是:

我收到以下错误:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.foo.bar.StagingTbl

我有一个复合主键,class 定义为:

@Embeddable
public class MyId implements Serializable {

        private static final long serialVersionUID = -99999999L;

        protected String compKey1;
        protected String compKey2;
        protected String compKey3;

       // setters/getters
}

my Abstract class:

        @MappedSuperclass
        public abstract class MyAbstractClass implements Serializable {

            protected static final long serialVersionUID = 7749572933971565230L;
            protected MyId myId;
            protected int col_A;
            protected Date col_B;
            protected String col_C

            public MyAbstractClass (String compKey1, String compKey2, String compKey3) {
              super();
              this.myId = new MyId(compKey1, compKey2, compKey3);
           }

            @EmbeddedId
            public MyId myId() {
                return myId;
            }
            public void setMyId(MyId myId) {
                this.myId= myId;
            }
          // getters/setters for other properties
}

我的混凝土class:

@Entity
@Table(name = "STG_TABLE" , schema="MYSCEMA")
public class StagingTbl extends MyAbstractClass implements Serializable {

}

标识符应该来自我正在扩展的 MyAbstractClass。我显然错过了一些愚蠢的东西。提前致谢。

您的错误是微不足道的:Hibernate 仅在名称遵循 Java Beans 约定的方法上找到 @EmbeddedId。

只需将您的 getter 更改为:

@EmbeddedId
public MyId getMyId() {
    return myId;
}