我基本上有以下课程:
@Entity
@Table( name="user" )
@Inheritance( strategy = InheritanceType.JOINED )
public abstract class User implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
@Column( name = "id" )
private Long id;
@Column( name = "email_address" )
private String emailAddress;
/* getters and setters not shown */
}
和
@Entity
@Table( name="admin" )
public class Admin extends User implements Serializable
{
private static final long serialVersionUID = 1L;
@Column( name = "role" )
private String role;
/* getters and setters not shown */
}
我希望 Hibernate 默认使用表DTYPE varchar(31)
中存在的user
列。当我的代码尝试保留一个新的 Admin 对象时,我看到以下记录到控制台:
Hibernate: insert into user (email_address) values (?)
Hibernate: insert into admin (role) values (?)
因此,Hibernate 没有尝试设置该user.DTYPE
列,并且它在数据库中保持为 NULL。我预计它将设置为Admin
.
我究竟做错了什么?我也尝试过明确设置@DiscriminatorColumn
User 类和@DiscriminatorValue
类Admin
(也尝试添加到 User )但无济于事。