0

I have 3 tables Consultant, Patient and Diagnosis. Diagnosis has attributes of both Consultant and Patient as foreign keys. I want to know how to show this in spring. What i have so far is, Consultant.java

   private String name;
   private String pos;
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "consultant")
    private List<Diagnosis> diagnosis;

Diagnosis.java

public class Request {
    private String token;
    private String comment;
    private boolean status;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "Patient_id")
    @JoinColumn(name = "Consultant_id") //not sure about this syntax
    private Consultant consultant;
    private Patient patient;

Patient.java

 private String name;
   private int pid;
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "patient")
    private List<Diagnosis> diagnosis;

Please is this how to go about it? I'm using postgresql.

1 Answer 1

2

Why are you annotating one field if you have 2 entities? Every relationship should be properly annotated:

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Patient_id")
private Patient patient;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Consultant_id")
private Consultant consultant;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.