简体   繁体   中英

Java Spring JPA - How to correctly map multiple tables with OneToMany and such

I am making a database project using Spring Boot and I have a model in mind that utilizes multiple tables. In this model of mine I thought about having a main table and using some of the attributes of this table as a primary key for the others, but I don't want to store, say, lists of others tables inside as seems to be the case for people when they use the @OneToMany tag and others. As you may guess, I'm new to database design.

Below, there is a simplified scheme of what I want to do. 在此处输入图像描述

My main questions here are:

  1. Is this good practice / good database design?
  2. Is this doable in Java Spring? If so, how? What annotations would I need to use and where?

Thank you in advance.

Person and Mobile number is the best example for one-to-many relationship. Because one person can have multiple mobile numbers, and for the mobile number perspective multiple mobile numbers refers to one person.

For the person entity there will be field like below: id, name, city, mobile_number_id [foreign key] which will holds id from mobile entity

For the mobile entity there will be field like below: id, mobile_number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM