Adding relationships between tables
Next, we create a new table called owner
that has a one-to-many relationship with the car
table. In this case, a one-to-many relationship means that the owner can own multiple cars, but a car can only have one owner. The following Unified Modeling Language (UML) diagram shows the relationship between the tables:
The following are the steps to create a new table:
- First, we must create the
Owner
entity and repository in thecom.packt.cardatabase.domain
package. TheOwner
entity and repository are created in a similar way to theCar
class.
The following is the source code of the Owner
entity class:
// Owner.java package com.packt.cardatabase.domain; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class Owner { @Id ...