我想在PatientEntity和MonitoringEntity之间创建一个oneToOne关系,但我有这个错误:实体类[class ch.lestoises.monitopsy.medication.entity.MonitoringEntity]中的属性[patient]的mappedBy值为[monitoringCode]在其拥有的实体类[class ch.lestoises.monitopsy.patient.entity.PatientEntity]中不存在。如果拥有的实体类是@MappedSuperclass,则这是无效的,并且您的属性应该引用正确的子类。这是我的代码:
@Entity
@Table(name = "patient")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "PatientEntity.findByNumber", query = "SELECT p FROM PatientEntity p WHERE p.patientNumber = :number"),
@NamedQuery(name = "PatientEntity.findAllPatient", query = "SELECT p FROM PatientEntity p ")
})
public class PatientEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "pk_patient")
private Integer pkPatient;
@NotNull
@Column(name = "name")
private String name;
@NotNull
@Column(name = "firstname")
private String firstname;
@OneToOne
@JoinColumn(name="pk_monitoring")
private transient MonitoringEntity monitoringCode;
} the Monitoring class : @Entity
public class MonitoringEntity {
@Id
@Column(name = "pk_monitoring")
private Integer pkMonitoring;
@OneToOne(mappedBy="monitoringCode")
private PatientEntity patient;
}
答案 0 :(得分:0)
我应该在PatientEntity中删除现场监控的瞬态和@JoinColumn