0

我正在尝试使用 play framework 使用 JPA 和 MYSQL 创建我的数据库,但是在映射 @oneToMany 时出现以下错误

    PersistenceException: Error with the Join on [models.Patient.progress].
    Could not find the matching foreign key for [id] in table[Results]? 
    Perhaps using a @JoinColumn with the name/referencedColumnName attributes swapped?

我的课程如下所示:

病人

@Entity
@Table(name = "Patients")
public class Patient
    extends User {


 @Id
 @Column(name = "idPatient")
 private int idPatient;
 @Constraints.Required
 private String medicalCoverage;
 @Constraints.Required
 private String disease;
 @Constraints.Required
 private int gradeDisease;
 @OneToMany(cascade = CascadeType.ALL, mappedBy = "patient",
        fetch = FetchType.LAZY)
 private List<Results> progress;
 @ManyToMany
 @JoinTable(name = "therapist_relation",
        joinColumns = {@JoinColumn(name = "idPatient")},
        inverseJoinColumns = {@JoinColumn(name = "idTherapist")})
 private List<Therapist> therapists;
 private int qAwardA;
 private int qAwardB;
 private int qAwardC;

结果

 @Entity
 @Table(name = "Results")
 public class Results {

  @Id
  @Column(name = "idResult")
  private int idResult;
  private Game game;
  @ManyToOne(optional = false, fetch = FetchType.LAZY)
  @JoinColumn(name="idPatient", referencedColumnName = "idPatient", nullable = false)
  private Patient patient;

  @OneToMany
  @JoinColumn(name="idTherapist", referencedColumnName = "idResult")
  private Therapist therapist;
  private int punctuation;
  private String description;

我的代码有什么问题?

4

1 回答 1

0

问题在于Patientin class的 @JoinColumn 注释Results

您正在使用referencedColumnName参数。

以下文档:

(可选)此外键列引用的列的名称。

所以,在这种情况下,这个论点是没有必要的。如果你想使用它应该看起来像referencedColumnName = "idResult"但正如我所说的那样没有必要。

于 2013-08-22T06:59:02.587 回答