Creating a many-to-one (or one-to-one) relationship between entities
In real-world applications, domain entities have relationships between them. In this section, we look at how Roo simplifies creating a many-to-one (or one-to-one) relationship between JPA entities.
The following figure shows the relationship between the FLIGHT_TBL
and FLIGHT_DESC_TBL
tables, which we will use as a reference to model our many-to-orelationship:
In the given figure, the FLIGHT_TBL
table contains scheduled flight details and the FLIGHT_DESC_TBL
table contains details of all the flights that an airline offers. Each record in the FLIGHT_TBL
table refers to exactly one FLIGHT_DESC_TBL
record. As there can be multiple flights from one city to another, the relationship between FLIGHT_TBL
and FLIGHT_DESC_TBL
is many-to-one. The FLIGHT_TBL
table is mapped to the FLIGHT_DESC_TBL
table by the FLIGHT_DESC_ID
foreign key. It is expected that if a FLIGHT_TBL
record is deleted, then the deletion is limited to the FLGHT_TBL...