简体   繁体   English

如何防止Hibernate在单表策略中生成像实体一样混乱的表?

[英]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.

相关问题 在以下情况下,如何从休眠单表策略中的列表中在Java 8中生成映射 - How to generate a map in java 8 from a list in hibernate single table strategy for the below scenario 如何在休眠状态下将实体属性映射到继承SINGLE_TABLE的实体? - How to map entity property to entities of inheritance SINGLE_TABLE in hibernate? 单表策略不起作用 Hibernate - SIngle table strategy doesn't working Hibernate java / hibernate-如何使用注释映射三个表/实体(休眠错误未映射到单个属性) - java/hibernate - how to map three tables/entities with annotation (hibernate error not mapped to a single property) 如何从休眠中的两个表生成单个对象? - How to generate a single object from two tables in hibernate? 使用Oracle和Hibernate的单表继承策略(或每个类层次结构的表) - Single table inheritance strategy (or table per class hierarchy) with Oracle and Hibernate 部署时,休眠中的@GeneratedValue(strategy = IDENTITY)不会生成关联(表) - @GeneratedValue(strategy = IDENTITY) in hibernate does not generate relation( table) when deployed 如何在休眠中使用单个表连接三个表? - How to join three tables using a single table in hibernate? 使用单表策略持久化 Hibernate 继承映射 - Persisting Hibernate Inheritance Mapping using Single Table strategy Hibernate从实体生成表不起作用 - Hibernate Generate Tables From Entities Doesn't Work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM