【发布时间】:2014-04-19 07:18:43
【问题描述】:
我们有一个旧表,我们不想在其中添加鉴别器列。 是否可以在没有鉴别器列的情况下拥有每个层次结构的表?
我的父类代码:
@Entity
@Table(name = "SHAPE1")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "Discriminator",
discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue(value = "S")
public class Shape {
@Id
@Column(name = "Shape_Id")
int shapeId;
@Column(name = "Shape_Name")
String shapeName;
public Shape() {
}
public Shape(int id, String shapeName) {
this.shapeId = id;
this.shapeName = shapeName;
}
// getters and setters
}
我的孩子班:
@Entity
@DiscriminatorValue(value = "R")
public class Rectangle extends Shape {
@Column(name = "Rectangle_Length")
int length;
@Column(name = "Rectangle_Breadth")
int breadth;
public Rectangle() {
}
public Rectangle(int id, String shapeName, int length, int breadth) {
super(id, shapeName);
this.length = length;
this.breadth = breadth;
}
// getters and setters
}
你可以在我上面的例子中看到,我必须使用一个鉴别器。
【问题讨论】:
标签: java hibernate inheritance