本文介绍了@AttributeOverride无法与继承一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试更改子类表中的列名,但是并没有使用@AttributeOverride批注进行更改.
I am trying to change the column name in the subclass table, but it is not getting changed with @AttributeOverride annotation.
@Entity @Table(name="emp")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class Employee {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
protected int id;
protected String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
@Table(name="RegularEmployee")
@AttributeOverrides({
@AttributeOverride(name="id", column=@Column(name="REGID")),
@AttributeOverride(name="name", column=@Column(name="REGNAME"))
})
public class RegularEmployee extends Employee {
private int salary;
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}
但是要创建的表结构是:
But the table structure getting created is:
员工:
CREATE TABLE EMP
(
ID NUMBER(10) NOT NULL,
NAME VARCHAR2(255 CHAR)
)
RegularEmployee:
RegularEmployee:
CREATE TABLE REGULAREMPLOYEE
(
ID NUMBER(10) NOT NULL,
NAME VARCHAR2(255 CHAR),
SALARY NUMBER(10) NOT NULL
)
推荐答案
它有助于读取 @AttributeOverride
的 JavaDoc :
使用 InheritanceType.TABLE_PER_CLASS
时,您可以简单地为 Employee
切换到 @MappedSuperclass
.如果仍然需要 EMP
表,则可以从该超类继承第二个类.
As you use InheritanceType.TABLE_PER_CLASS
you can simply switch to @MappedSuperclass
for Employee
. If you still need the EMP
table you can inherit a second class from that superclass.
这篇关于@AttributeOverride无法与继承一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!