简体   繁体   English

Hibernate继承:模式验证:缺少列

[英]Hibernate inheritance: Schema-validation: missing column

I am trying to implement inheritance in Hibernate with strategy InheritanceType.JOINED . 我正在尝试使用策略InheritanceType.JOINEDHibernate实现InheritanceType.JOINED However, when starting up the application it fails with the exception: 但是,在启动应用程序时,它会失败并出现以下异常:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [EMAIL] in table [CLIENT]

I don't know why it is looking for the field email in the Client table, since the entity model specifies it is in the abstract superclass - User . 我不知道为什么它要在Client表中查找字段email ,因为实体模型指定它在抽象的超类User Client has only fields specific for it. 客户只有特定的字段。

Here is how my entity model looks. 这是我的实体模型的外观。

UserTable.java UserTable.java

@Entity
@Table(name = "USER")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class UserTable implements Serializable {

    private static final long serialVersionUID = 1L;

    @Column(name = "USER_ID", nullable = false)
    private Long userId;

    @EmbeddedId
    private UserTablePK userTablePK;

    @Column(name = "PASSWORD", nullable = false, length = 512)
    private String password;

    @Column(name = "FIRSTNAME", nullable = false, length = 256)
    private String firstName;

    public UserTable() {
    }

    public UserTable(Long userId, String email, String password, String firstName) {
        this.userId = userId;
        this.userTablePK = new UserTablePK(email);
        this.password = HashCalculator.calculateSha256Hash(password, SecurityConstants.saltConstant());
        this.firstName = firstName;
    }
// get, set
}

UserTablePK.java UserTablePK.java

@Embeddable
public class UserTablePK implements Serializable {

    @Column(name = "EMAIL", nullable = false, length = 256)
    private String email;

    public UserTablePK() {
    }

    public UserTablePK(String email) {
        this.email = email;
    }

ClientTable.java ClientTable.java

@Entity
@Table(name = "CLIENT")
public class ClientTable extends UserTable implements Serializable {

    @Column(name = "WEIGHT")
    private String weight;

    @Column(name = "HEIGHT")
    private Integer height;

    public ClientTable() {
    }

    public ClientTable(Long clientId, String weight, Integer height, String email, String password, String firstName) {
        super(clientId, email, password, firstName);
        this.weight = weight;
        this.height = height;
    }
}

Again, why is it looking for email field in the subclass table? 同样,为什么要在子类表中查找email字段? I used Liquibase for Schema generation, and I checked - the schema is correct. 我使用Liquibase进行模式生成,并检查了-模式是否正确。 There is no email in the Client table, it's only in the User table as it should be. Client表中没有email ,它只是应该在“ User表中。 The entity model corresponds to that, so what's the issue? 实体模型与此相对应,那么问题是什么?

Because it's the pk in the parent class .... You need to refer to the parent table from the child table, hence you also need an 'email' column in the child table to refer through it back to the parent table 因为它是父类中的pk...。您需要从子表中引用父表,因此,您还需要在子表中有一个“ email”列,以将其通过引用返回到父表

EDIT : You will just need to add a column "email" in 'CLIENT' table to just use the JPA default config .... if you want to edit the FK that references from child to parent you will need to override @PrimaryKeyJoinColumn as described here 编辑:您只需要在“客户”表中添加一列“电子邮件”即可使用JPA默认配置....如果要编辑从子对象到父对象的FK,则需要覆盖@PrimaryKeyJoinColumn作为在这里描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate + JPA:模式验证:缺少列 - Hibernate + JPA: Schema-validation: missing column Hibernate 5 模式验证:缺少带有 HBM 文件的表 - Hibernate 5 Schema-validation: missing table with HBM files Java Spring Hibernate Schema-Validation:缺少表 - Java Spring Hibernate Schema-Validation: Missing Table 架构验证:缺少表 [hibernate_sequences] - Schema-validation: missing table [hibernate_sequences] 使用Schema-validation验证除dbo结果以外的其他模式中的休眠访问表:缺少表 - Hibernate acessing table in schema other than dbo results with Schema-validation: missing table Hibernate:模式验证:缺少表 - 区分大小写 Mysql 模式标识符变为大写 - Hibernate: Schema-validation: missing table - case-sensitive Mysql schema identifier turned upper-case Spring Boot 项目由于 Schema-validation 无法运行:缺少序列 [hibernate_sequence] - Spring Boot project fails to run because of Schema-validation: missing sequence [hibernate_sequence] Java Hibernate -Mysql Schema-validation:列中遇到错误的列类型 - Java Hibernate -Mysql Schema-validation: wrong column type encountered in column 模式验证:使用Flyway的Hibernate生成的SQL代码缺少表[…]错误消息 - Schema-validation: missing table […] error message using flyway for a SQL code generated by Hibernate SqlServer2016,Hibernate 模式验证:缺少表,但表存在于数据库中 - SqlServer2016, Hibernate schema-validation: Missing table, but table exists in db
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM