Author | Message |
---|---|
agedam
Posts: 15
|
Posted 13:37 Apr 29, 2013 |
Hello, I am still little confused about the relationship between User and Role. I understood that a Role can be assigned to many users, but a User can have only one role right? that of a normal user and a lawyer.
|
cysun
Posts: 2935
|
Posted 14:50 Apr 29, 2013 |
It's up to you to decide how many roles a user can have. You can say a user can only have one role (either Regular or Lawyer), or a user can have two roles (Regular and Lawyer). |
agedam
Posts: 15
|
Posted 18:35 Apr 29, 2013 |
So I am actually opting for the first option..which is that a user can only have one role (either Normal or Lawyer)...For this logic it will be ManyToOne I assume...thats why in Role class I used @ManyToOne @JoinColumn(name = "user_id")
private User user;
I was just wondering why was the design wrong.
|
cysun
Posts: 2935
|
Posted 22:00 Apr 29, 2013 |
First of all, if a user can only have one role, then you really don't need "role". A User class and a Lawyer class would do just fine. Secondly, if you do want to use role, then there should be a Role reference in the User class, not a User reference in the Role class. The way you are doing it implies that a role can only be assigned to one user, which is obviously not the case. |