Lets say if I have two entities like this,
Users Entity:
public class Users {
@Basic
@Column(name = "USER_NAME")
private String name;
@Basic
@Column(name = "USER_ADDRESS")
private String address;
@ManyToOne
@JsonBackReference
@JoinColumn(name = "PERSON_ID")
private Person personData;
}
Person Entity:
public class Person {
@Id
@Column(name = "PERSON_ID")
private Long personId
@Basic
@Column(name = "USER_ADDRESS")
private String address;
@OneToMany(mappedBy="personData", cascase = CascadeType.ALL, orphanRemoval = true)
@JsonManagedReference
List<Users> users;
}
Now, how do I create DTOs for these two entities when I am doing unit testing? Also, when I try to access these entities in my service, it gives me StackOverflow Exception because of nested entities.