Home Hibernate inheritance: Schema-validation: missing column
Reply: 0

Hibernate inheritance: Schema-validation: missing column

user2796
1#
user2796 Published in June 23, 2018, 4:36 am

I am trying to implement inheritance in Hibernate with strategy 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 has only fields specific for it.

Here is how my entity model looks.

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

@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

@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? I used Liquibase for Schema generation, and I checked - the schema is correct. There is no email in the Client table, it's only in the User table as it should be. The entity model corresponds to that, so what's the issue?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.336105 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO