Issue
I'm getting ERROR: syntax error at end of input while trying to execute the query below:
SELECT appointment FROM Appointment appointment LEFT JOIN DoctorFacilityAppointment dfa
Can someone tell me why I'm getting this error?
Appointment class
public class Appointment implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name="start_time")
private LocalDateTime startTime;
@Column(name="is_valide")
private boolean isValid;
@ManyToOne
@JoinColumn(name = "patient_id", referencedColumnName = "id")
private Patient patient;
}
DoctorFacilityAppointment
public class DoctorFacilityAppointment implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@ManyToOne
@JoinColumn(name = "appointment_id", referencedColumnName = "id")
private Appointment appointment;
@ManyToOne
@JoinColumn(name = "doctor_service_id", referencedColumnName = "id")
private DoctorFacility doctorFacility;
}
Solution
JPQL/HQL join should refer to the appropriate entity's association or component/embedded attributes.
So, the correct query should look like this:
select app from DoctorFacilityAppointment dfa left join dfa.appointment app
Answered By - SternK