[英]How to prevent Hibernate to generate tables as mush as Entities in single table strategy?
The code below is my object model and I need to create JUST two tables for these entities. 下面的代码是我的对象模型,我需要为这些实体创建两个表。 One for
InheritanceType.JOINED
strategy and the other for InheritanceType.SINGLE_TABLE
strategy. 一个用于
InheritanceType.JOINED
策略,另一个用于InheritanceType.SINGLE_TABLE
策略。 But unfortunately Hibernate creates tables as mush as entities. 但是不幸的是,Hibernate创建的表就像实体一样。 What should I do?
我该怎么办?
Thanks in advance. 提前致谢。
@MappedSuperClass
public abstract class EntityObject implements Cloneable, Serializable {
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class SuperParent extends EntityObject{
private String lastName;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "d_type", discriminatorType = DiscriminatorType.STRING)
public class Parent extends SuperParent {
private String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
@Entity
@DiscriminatorValue("Child1")
public class Child1 extends Parent {
private String age;
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
@Entity
@DiscriminatorValue("child2")
public class Child2 extends Parent {
private String hairColor;
public String getHairColor() {
return hairColor;
}
public void setHairColor(String hairColor) {
this.hairColor = hairColor;
}
}
It is not supported to mix joined inheritance strategy with other inheritance strategies. 不支持将联接的继承策略与其他继承策略混合使用。 Hibernate supports only mixing of table-per-class with table-per-subclass inheritance.
Hibernate仅支持按类继承表与按子继承表的混合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.