2014-03-14 39 views
1

我们有一个遗留表,我们不希望它通过添加鉴别器列来更改。 是否有没有鉴别器列的tablePerHierarchy。休眠状态下没有鉴别器列的tablePerHierarchy策略

下面是我的父母和子女类代码

@Entity 

@Table(name = “SHAPE1”) @Inheritance(策略= InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(NAME = “鉴别”,discriminatorType = DiscriminatorType.STRING) @DiscriminatorValue(值= “S”)

公共类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(值= “R”) 公共类矩形延伸的部分{

@Column(name = "Rectangle_Length") 
int length; 
@Column(name = "Rectangle_Breadth") 
int breadth; 

// getters and setters 

public Rectangle() { 

} 

public Rectangle(int id, String shapeName, int length, int breadth) { 
    super(id, shapeName); 
    this.length = length; 
    this.breadth = breadth; 
} 

// getters and setters 

}

你可以看到我上面的示例我不得不使用鉴别​​器。 如果有谁知道有没有tablePerHierarchy鉴别列请帮我

回答

0

SINGLE_TABLE是一个非常强大的策略,但有时,特别对遗留系统,你不能添加额外的鉴别列。为此,Hibernate引入了鉴别器公式的概念:@DiscriminatorFormula是@DiscriminatorColumn的替代品,并使用SQL片段作为鉴别器解析的公式(不需要专用列)。

@Entity @DiscriminatorFormula( “情况下forest_type为null,则0,否则,forest_type结束”) 公共类森林{...}