Join-mapping to load data from multiple tables
Components address a situation where multiple domain classes need to be mapped to a single database table. If you have the exact opposite situation, where a single domain entity needs to be mapped to multiple database tables, then you can use joins. This feature comes with a caveat though—the tables being joined must have a one-to-one relation between them. You would soon agree that this caveat makes sense.
To understand this better, we would assume that in our employee benefits domain model, we do not have an Address
entity, and all address fields are present on the Employee
entity itself. Moreover, we would also assume that in the database, address fields are stored in a different table named Address,
having a one-to-one relation with Employee
table. For the sake of simplicity, we would ignore other fields on Employee
entity. Following is how the Employee
entity with details relevant to this discussion looks:
public class Employee { public...