我有一个抽象超类“RessourceMaterielle”和一个实体派生类“Vehicule”。我在 sperclass 和另一个类“本地化”之间有一个 1 对 1 的映射。抽象超类不在数据库中表示。我希望派生类继承超类和本地化之间的映射,以便 Hibernate 看到车辆和本地化之间的映射。那可能吗?
超类:
@MappedSuperclass
public abstract class RessourceMaterielle extends ObjetMetier {
private String nom = null;
private Localisation localisation = null;
@Column(name = "`NOM`")
public String getNom() {
return this.nom == null ? null : new String(this.nom);
}
public void setNom(String nom) {
this.nom = new String(nom);
}
@OneToOne(cascade={CascadeType.ALL})
@JoinColumn(name="`LOCALISATION`")
public Localisation getLocalisation() {
return this.localisation == null ? null : this.localisation.clone();
}
public void setLocalisation(Localisation localisation) {
this.localisation = localisation.clone();
}
public RessourceMaterielle(){
}
}
车辆:
@Entity(name = "VEHICULE")
@Table(name = "`VEHICULE`")
public class Vehicule extends RessourceMaterielle {
public Vehicule() {
}
}
本土化:
@Entity(name = "LOCALISATION")
@Table(name = "`LOCALISATION`")
public class Localisation extends ObjetMetier {
private double lon = -1111;
private double lat = -1111;
private RessourceMaterielle ressourceMaterielle;
@OneToOne(cascade = { CascadeType.ALL }, mappedBy = "localisation")
public RessourceMaterielle getRessourceMaterielle() {
return (RessourceMaterielle) (this.ressourceMaterielle == null ? null : this.ressourceMaterielle.clone());
}
public void setRessourceMaterielle(RessourceMaterielle ressourceMaterielle) {
this.ressourceMaterielle = ressourceMaterielle;
}
@Column(name = "`LON`")
public double getLon() {
return this.lon;
}
public void setLon(double lon) {
this.lon = lon;
}
@Column(name = "`LAT`")
public double getLat() {
return this.lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public Localisation() {
}
public Localisation(double lon, double lat) {
this.setLon(lon);
this.setLat(lat);
}
}
当我运行将车辆持久保存到数据库中的测试时,我收到以下错误:
org.hibernate.AnnotationException: Unknown mappedBy in: com.organisme.model.localisation.Localisation.ressourceMaterielle, referenced property unknown: com.organisme.model.ressource.RessourceMaterielle.localisation
有什么解决办法吗?
问候。