my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes How to create Entity bean relationship for this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to create Entity bean relationship for this?" Watch "How to create Entity bean relationship for this?" New topic

How to create Entity bean relationship for this?

Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
I meet a difficult in the following problems...
In my project, there are 4 tables:
user, role, permission, and role_permission
The following are the details of these 4 tables:
UserName varchar(10), primary key
RoleID int
RoleID int, primary key
RoleName varchar(30)
PermissionID int, primary key
PermissionName varchar(30)
RoleID int, primary key
PermissionID int, primary key
Each user should have a RoleID. In the table role_permission, it is used to store which role can access the permission page. Because each role can have the access more than one page, RoleID and PermissionID are the primary key.
Now, I want to get which PermissionName can have access for a specified user. How should I create this relationship? Moreover, which entity beans should I create? Thanks!
Stephen Lee
Frank Xia

Joined: Apr 27, 2002
Posts: 3
Hi, Stephen:
I think you can create three CMP, RoleBean, UserBean and PermissionBean. R and U have an one- to-many relationship, you user roleID in the U table to map the relationship. R and P have a many-to-many relationship, you can user R-P table to map this relationship. In my opinion, you don't need to define any primary key in the R-P table. To get the permissions of a user, you use UserLocal.getRole().getPermissions() to get a Collection of permissions the user has.
Good Luck.
Consider Paul's rocket mass heater.
subject: How to create Entity bean relationship for this?
Similar Threads
No metadata was found for type "class java.util.ArrayList". The class is not enhanced
Java Persistence API Entities Enthuware Wrong Answer
plz have a glance at this query
uni-directional association (or Directed Association ) vs dependency
Storing XML in the Database