Reputation: 2360
I have two class, User
and Status
, while a user will have a number of status, this is naturally Many-to-One
relation and can be easily mapped to DB Tables.
However, the requirement also need User to maintain its “current” status, i.e., in the User
Table, it need to have a foreign-key to the Status
table. The result of this is having two foreign-keys between two tables in the opposite direction.
One obvious problem of this is once the records are inserted into the two tables, I can delete neither of them cause deleting from one table will violate the other table's foreign-key.
What is the best Design for this situation?
Upvotes: 2
Views: 279
Reputation: 1931
Do you have to keep the status in a separate table ? can it not be just represented by a java enum, and the User would have a status property. Something like this:
public enum UserStatus {
X, Y, Z;
}
public class User {
private UserStatus status;
...
}
Upvotes: 1
Reputation: 700
I hope it helped you !
Upvotes: 1