Java @抽象MappedSuperclass中的许多
我的hibernate项目有以下设计:Java @抽象MappedSuperclass中的许多,java,hibernate,annotations,Java,Hibernate,Annotations,我的hibernate项目有以下设计: @MappedSuperclass public abstract class User { private List<Profil> profile; @ManyToMany (targetEntity=Profil.class) public List<Profil> getProfile(){ return profile; } public void setPr
@MappedSuperclass
public abstract class User {
private List<Profil> profile;
@ManyToMany (targetEntity=Profil.class)
public List<Profil> getProfile(){
return profile;
}
public void setProfile(List<Profil> profile) {
this.profile = profile;
}
}
@Entity
@Table(name="client")
public class Client extends User {
private Date birthdate;
@Column(name="birthdate")
@Temporal(TemporalType.TIMESTAMP)
public Date getBirthdate() {
return birthdate;
}
public void setBirthdate(Date birthdate) {
this.birthdate= birthdate;
}
}
@Entity
@Table(name="employee")
public class Employee extends User {
private Date startdate;
@Column(name="startdate")
@Temporal(TemporalType.TIMESTAMP)
public Date getStartdate() {
return startdate;
}
public void setStartdate(Date startdate) {
this.startdate= startdate;
}
}
@MappedSuperclass
公共抽象类用户{
私人名单简介;
@多个(targetEntity=profile.class)
公共列表getProfile(){
回报曲线;
}
公共无效设置配置文件(列表配置文件){
this.profile=profile;
}
}
@实体
@表(name=“客户”)
公共类客户端扩展用户{
私人生日;
@列(name=“生日”)
@时态(TemporalType.TIMESTAMP)
公共日期getBirthdate(){
返回出生日期;
}
公共无效设置出生日期(日期出生日期){
这个。生日=生日;
}
}
@实体
@表(name=“employee”)
公共类Employee扩展用户{
私人日期开始日期;
@列(name=“startdate”)
@时态(TemporalType.TIMESTAMP)
公共日期getStartdate(){
返回起始日期;
}
公共作废设置开始日期(日期开始日期){
这个.startdate=startdate;
}
}
正如您所看到的,用户hat与概要文件有很多关系
@Entity
@Table(name="profil")
public class Profil extends GObject {
private List<User> user;
@ManyToMany(mappedBy = "profile", targetEntity = User.class )
public List<User> getUser(){
return user;
}
public void setUser(List<User> user){
this.user = user;
}
}
@实体
@表(name=“profil”)
公共类Profil扩展GObject{
私有列表用户;
@ManyToMany(mappedBy=“profile”,targetEntity=User.class)
公共列表getUser(){
返回用户;
}
公共void setUser(列表用户){
this.user=用户;
}
}
如果现在尝试创建员工,则会出现hibernate异常:
org.hibernate.AnnotationException:使用
针对@OneToMany或@ManyToMany的目标
未映射的类:
de.ke.objects.bo.profile.Profil.user[de.ke.objects.bo.user.user]
我如何使用多个关系在超类
User
上进行配置,使其适用于客户端
和员工
?问题在于对用户的引用,而用户不是实体。外键只能引用一个表。要么使用@ManyToAny,它可以处理多个表,要么使用@heritance(strategy=InheritanceType.SINGLE_TABLE),它将把所有实体放在一个表上
以下是有关hibernate中继承的文档: