How to Join multiple tables in Spring WebFlux for Relational Database?
In Spring Boot, in order to join two tables, we can perform different mappings (@OneToOne, @ManyToOne, @OneToMany). One example is shown below for mapping between doctor and patient.
Doctor Class (Entity)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Doctor {
@Id
private int did;
private String dname;
private String specs;
}
Patient Class (Entity)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Patient {
@Id
private int id;
private String name;
private int age;
@OneToOne(targetEntity = Doctor.class,cascade = CascadeType.ALL)
@JoinColumn(name = "Id_Fk")
private Doctor doctor;
}
For Spring Webflux, I have created two tables (postgresSQL) shown below, their respective repositories, a handler and a router in IntelliJ. How to code the above in Spring Webflux as we can't use @Entity or any mapping annotations there?
Doctor Table
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Doctor {
@Id
private int did;
private String dname;
private String specs;
}
Patient Table
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Patient {
@Id
private int pid;
private String name;
private int age;
}