在生成表的時候遇到了這樣一個問題,將主鍵放到父類中去,其他的實體表繼承主鍵
@Entity
@Table(name = "base_table")
public class BaseEntity {
public BaseEntity() {
}
@Id
@GenericGenerator(name = "idGenerator", strategy = "uuid")
@GeneratedValue(generator = "idGenerator")
@Column(name = "id", unique = true, nullable = false)
protected String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
如果這樣,那么生成的主表,會包含其他被繼承的表的所有不重復的字段
應改成:
@Entity
@Table(name = "base_table")
@MappedSuperclass
public class BaseEntity {
public BaseEntity() {
}
@Id
@GenericGenerator(name = "idGenerator", strategy = "uuid")
@GeneratedValue(generator = "idGenerator")
@Column(name = "id", unique = true, nullable = false)
protected String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
僅僅多加了一個
@MappedSuperclass
