Rohit
Rohit

Reputation: 868

JPA - Join Two tables

I have two tables, namely

USER_ROLE  {user_id, Role} PK {user_id, role}
ROLE_PERMISSION  {role, permission} PK {role, permission}
  1. A User can have multiple Roles.
  2. A Role can be mapped to multiple Permissions.

I have a entity - USER that maintains information about the User. This info is fetched via LDAP (not DB) on first login. Now, for my authorization aspects, I need to also fetch dtls on User's permissions from above mentioned tables.

So I would imagine adding attributes to my existing USER entity

USER {
   user_id, 
   first_name, 
   last_name,
   etc

   // Authorization
   List<String> roles;
   List<String> permissions;
}

Can someone pls help how I can use JPA to populate the roles and permissions Lists? Looked over internet, can't figure it out. thanks

Upvotes: 0

Views: 390

Answers (1)

James
James

Reputation: 18389

I would create a USER table in your database and map it to a User object with the role and permissions. The User object then would include additional LDAP data.

Without a USER table you have nothing to map to.

Otherwise just query for the database using native SQL queries and populate your LDAP user object yourself.

Upvotes: 1

Related Questions