我有我的Hibernate項目如下設計:@ManyToMany在抽象MappedSuperclass
@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="kunde")
public class Kunde 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;
}
}
正如你所看到的,用戶帽子多對多關係簡介。
@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;
}
}
如果我現在嘗試創建一個員工,我得到一個休眠例外:
org.hibernate.AnnotationException:@OneToMany使用 或@ManyToMany目標 未映射類: 德.ke.objects.bo.profile.Profil.user [de.ke.objects.bo.user.User]
我如何使用多對多-關係簡介在超用戶,所以它適用於Kunde和Empl oyee?
在此先感謝。
嗨,你能解決這個問題?我面臨同樣的問題。 – tarkikshah 2017-06-22 12:13:59