Can someone help me with this problem? I tried with mapstruct and it works just fine but only for entities which doesn't have bidirectional relationship.
For instance I have the entities:
@Entity
public class Pacients implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int pacientId;
// bi-directional many-to-one association to Doctori
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "doctorId")
private Doctors doctor;
//setters and getters
}
and
@Entity
public class Doctors implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int doctorId;
// bi-directional many-to-one association to Pacienti
@OneToMany(mappedBy = "doctor")
private List<Pacients> pacients;
//setters and getters
}
DTO's:
public class PacientsDto implements Serializable {
private int pacientId;
private Doctors doctor;
//setters and getters
}
public class DoctorsDto implements Serializable {
private int doctorId;
private List<Pacients> pacients;
//setters and getters
}
When I try to map them on dto's I get an StackOverflowError because of that birectional relationship.
Any idea how can I solve this? I will also accept a solution without using mapstruct.
If any details needed please let me know. Thank you!