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

Time:01-06

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. enter image description here

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.

CodePudding user response:

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

  • Related