I have two JPA2 entity classes that refer to each other
class Person {
int id;
String name;
@ManyToOne(fetch = FetchType.LAZY)
Company company;
}
class Company{
int id;
String name;
@ManyToOne(fetch = FetchType.LAZY)
Person representative;
}
Having this data:
Company company1 = Company(1,"Company1", 2)
Company company2 = Company(2,"Company2", 1)
Person person1 = Person (1,"Person1", 1)
Person person2 = Person (2,"Person2", 2)
person2 works for company2, whose representative is person1 which works for company1 whose representative is once again person2
I know that Dozer is capable of copying this model to DTO's (CompanyDTO and PersonDTO). In my tests, they work and have infinite levels of recursion. I understand this is because Dozer uses the same instantiated objects as references in the DTO's.
My question is, what if there were thousands of persons who represent hundreds of companies, couldn't the graph of a PersonDTO instance be too large to handle? How can I specify some sort of limit for this situation?
There are two possible strategies to handle this situation.