简体   繁体   中英

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. But unfortunately Hibernate creates tables as mush as entities. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM