JPA entity 使用繼承關係時,發生 Cannot use identity column key generation with mapping for: {class xxxx} 如何解決
先定義Root(父類) 的表如下
記得把 Id 一定要設定成 GenerationType.TABLE
@SuppressWarnings("serial") @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class AbsEnum implements Serializable { private Integer id; private String name; private String enName; private Integer operatorId; private Date updatedAt; @Id @Column(nullable = false, columnDefinition = JpaConstant.COLUMN_DEFIN_ID) @GeneratedValue(strategy = GenerationType.TABLE) public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEnName() { return enName; } public void setEnName(String enName) { this.enName = enName; } public Integer getOperatorId() { return operatorId; } public void setOperatorId(Integer operatorId) { this.operatorId = operatorId; } public Date getUpdatedAt() { return updatedAt; } public void setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; } }
記得把 Id 一定要設定成 GenerationType.TABLE
留言
張貼留言