我对hibernate有疑问。我有类User,其中包含有关用户的基本信息。
[InsuredName] = [INDEX(Data,RetrievalRow,InsuredNameIndex)]
现在我需要使用有关用户
的扩展信息创建类UserFullpublic class User {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
@Column(name = "surname")
private String surname;
@Column(name = "photo_url")
private String photoURL;
我如何用hibernate实现这样的扩展?两个类都引用相同的表" user"。
答案 0 :(得分:0)
此代码将执行您想要实现的目标
@Entity
@Table(name="User")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE) //Least normalisation strategy
public class User
{
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
@Column(name = "surname")
private String surname;
@Column(name = "photo_url")
private String photoURL;
}
@Entity
@Table(name="UserFull")
public class UserFull extends User {
@Column(name = "email")
private String email;
@Column(name = "date_birthday")
private Date dateBirthday;
@Column(name = "date_registration")
private Date dateRegistration;
}