Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need a bit of explanation about bidirectional relation between two entity beans.

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
thank you for reading my post.
Can some one please tell me what could be possible tables and table relation for following code?

House.java:




Student.java




thanks
 
Tong Wang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you are asking about the SQL table structure for storing these entity beans. As for the SQL part, there is no difference between bidirectional and unidirectional relations. You will have the same primary key/foreign key constraint in the tables, or you will have the same join table.

In other words, you will have primary keys in both tables and a foreign key in the many-side table that refers to the primary key of the one-side table.

Or, you will have a join table with two foreign key columns: one referring the primary key of the one-side table, the other referring the primary key of the many-side table.

Hope this helps.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
House table has a house_id PK

Student table has a student_id PK and a house_id Foreign Key (FK)

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic