0

我有一个与 PatientVisitObject.java 一对一映射的 PatientVisit.java:

@Entity
@Table(name = "P_Visit")
public class PatientVisit extends Bean {
  @Id
  @Column(name = "PATIENT_VISIT_SEQ")
  private Long patientVisitSeq;
  @Column(name = "PATIENT_FIRST_NM")
  private String firstName;
  @Column(name = "PATIENT_LAST_NM")
  private String lastName;
  @Column(name = "PATIENT_MIDDLE_NM")
  private String middleName;
  @OneToOne
  private PatientVisitObject pvo;
}

PatientVisitObject.java 有一个复合键。我需要将 key.patientVisitSeq 映射到 PatientVisit.java 中的 patientVisitSeq。

@Entity
@Table(name = "Patient_V_O")
public class PatientVisitObject extends Bean {
  @Id
  private PatientVisitObjectKey key;
  @Column(name = "FIELD")
  private String field;
}

这是关键:

@Embeddable
public class PatientVisitObjectKey implements Serializable {
  @Column(name = "PATIENT_VISIT_SEQ")
  private Long patientVisitSeq;
  @Column(name = "PATIENT_VISIT_OBJECT_SEQ")
  private Long patientVisitObjectSeq;
}

我尝试使用 @JoinTable 注释,但无法正确使用。有人可以给我一些指导。谢谢。

4

1 回答 1

1

您需要使用双向映射PatientVisit作为关系的反面:

public class PatientVisit extends Bean {
    ...
    @OneToOne(mappedBy = "pv")
    private PatientVisitObject pvo;
    ...
}

public class PatientVisitObject extends Bean {
    @EmbeddedId
    private PatientVisitObjectKey key;

    @OneToOne 
    @MapsId("patientVisitSeq")
    private PatientVisit pv;

    ...
}

也可以看看:

于 2013-04-16T19:21:51.580 回答