2013-08-22 2 views
0

내가 JPA와 MYSQL 플레이 프레임 워크를 사용하지만, PersistenceException : @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? 

내 클래스

는 다음과 같은 보이는 @OneToMany를 매핑 할 때 i'am 다음과 같은 오류가 내 데이터베이스를 만들려고하고를 사용하는 경우 :

환자

@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; 

내 코드에 어떤 문제가 있습니까?

답변

0

Patient에 대한 @JoinColumn 주석이 문제가되는 것은 Results입니다.

referencedColumnName 매개 변수를 사용 중입니다. 문서에 따라

는 :

(Optional) The name of the column referenced by this foreign key column.

그래서,이 경우이 인수는 필요하지 않습니다. 사용을 원한다면 referencedColumnName = "idResult"처럼 보일 것입니다.

+0

만약 내가 당신이 말하는이 새로운 오류 havin 오전 : PersistenceException : 조인에 [models.Results.patient] 오류가 발생했습니다. [null]에 대한 로컬 일치를 찾을 수 없습니다. 아마도 @JoinColumn에서 오류가 발생했습니다. – user1371176