How do you best handle the mapping between a database entity class structure to a data transfer object (DTO) class structure where classes can appear multple times in the hierarchy.
Let's say you have the database entity classes with JPA annotation which is left out here:
class DBCompany {
String companyName;
DBPerson employee;
DBHouse factory;
}
class DBPerson {
String Name;
DBHouse residentialBuilding;
}
And the corresponding DTO structure
class
DTOCompany {
String companyName;
DTOPerson employee;
DTOHouse factory;
}
class DTOPerson {
String Name;
DTOHouse residentialBuilding;
}
And then I want to use strict mapping when converting back and forth between the two hierarchies. Do I then have to define explicit mappings between each and every class member in the classes in order to be completely safe nothing get converted using wrong mapping? Or is it handled if you just name the class members identically?