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

Hibernate inheritance: Schema-validation: missing column

user7130
1#
user7130 Published in September 20, 2018, 12:45 pm

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?

share|improve this question
  • why have a separate PK class just to contain a single field?! let's complicate life ... – user8558216 Feb 10 at 13:18

1 Answer 1

active oldest votes
up vote 2 down vote accepted
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO