I posted it because I had a hard time implementing it as a memorandum for myself.
RestaurantsEntity.java
@Entity
@Table(name="restaurants")
public class RestaurantsEntity {
//Description of each field variable Omitted ……
@OneToMany(mappedBy="restaurantId")
private List<RestaurantMenuEntity> restaurantMenuEntityList;
//The following setter/getter abbreviation ……
}
The field on one side of "one-to-many" holds a collection of entities on the other side (private List
Annotate @OneToMany and specify the field of the multi-sided entity to be associated with mappedBy (mappedBy = "restaurantId").
RestaurantMenuEntity.java
@Table(name="restaurantMenu")
public class RestaurantMenuEntity {
//Description of each field variable Omitted ……
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "restaurantId")
private RestaurantMenuEntity restaurantId;
//The following setter/getter abbreviation ……
}
The "many-to-one" multi-sided field holds one-sided entities (private RestaurantMenuEntity restaurantId;).
The relationship is defined by adding the @ManyToOne annotation.
The name specifies the column name used to join the related tables (name = "restaurantId").
I don't understand everything yet, but I was able to implement it for the time being.