我正在尝试使用策略 InheritanceType.JOINED
在 Hibernate
中实现继承。然而,当启动应用程序时,出现了异常:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [EMAIL] in table [CLIENT]
我不知道为什么它在
Client
表中查找email
字段,因为实体模型指定它在抽象的超类-User
中。Client仅具有特定于其自身的字段。以下是我的实体模型样式。 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;
}
}
为什么它在子类表中查找email
字段呢?我使用Liquibase进行模式生成,并检查了——模式是正确的。在Client
表中没有email
,只有在User
表中才有,这是应该的。实体模型与此相对应,所以问题出在哪里呢?