我正在使用Spring-Boot 1.5.10和spring-boot-starter-data-jpa。我有一个临时表和一个生产表,两者都有相同的结构只是不同的表名。列是:
我收到以下错误:
引起:org.hibernate.AnnotationException:未指定标识符 for entity:com.foo.bar.StagingTbl
我有一个复合主键,类定义为:
@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
}
我的具体课程:
@Entity
@Table(name = "STG_TABLE" , schema="MYSCEMA")
public class StagingTbl extends MyAbstractClass implements Serializable {
}
标识符应该来自我正在扩展的MyAbstractClass。我显然错过了一些愚蠢的事情。提前谢谢。
答案 0 :(得分:0)
你的错误是微不足道的:Hibernate只在方法上找到@EmbeddedId,如果它的名字遵循Java Beans约定。
只需将你的吸气剂更改为:
@EmbeddedId
public MyId getMyId() {
return myId;
}