• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting up a One To Many Joins Against a Bridge Table using JPA

 
James Dekker
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am new to JPA...

I have the following preexisting tables inside a MySQL 5 database:

App
User
User_App_Bridge

The relationship(s) are mapped to the User_App_Bridge table (as the name implies, a bridge) amongst App and User as a One to Many cardinality.

The E-R diagram:

User ------ User_App_Bridge------ App

1 User is associated with many apps inside the User_App_Bridge table.

1 App is associated with many users inside the User_App_Bridge table.

The DDL for the User_App_Bridge table:



Lets say that I have the following JPA Annotated Classes which are mapped to these tables:




Question(s):

(1) Is this (the block inside the @JoinTable) the correct way to do the one to many mapping for User and App entites with the UserAppBridge?

(2) Inside the @JoinTable should the column & referencedColumnName be assigned to the SQL value (e.g. name="User_Id" , referencedColumnName = "User_Id")
or should it be the Java reference name (e.g. name="userId" , referencedColumnName = "userId")?

(3) Inside the inverseJoinColumns code black, is the unique = true necessary (what is it for)?

(4) Do I need to do anything else inside the UserAppBridge class (for connecting to App and User)?

Thank you for taking the time to read this...
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a Many-to-Many, so why not model it as that?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic