hibernate - Database design consideration on foreign-key both way between two tables -
i have 2 class, user
, status
, while user have number of status, naturally many-to-one
relation , can mapped db tables.
however, requirement need user maintain “current” status, i.e., in user
table, need have foreign-key status
table. result of having 2 foreign-keys between 2 tables in opposite direction.
one obvious problem of once records inserted 2 tables, can delete neither of them cause deleting 1 table violate other table's foreign-key.
what best design situation?
- in status table , add column determine whether status record "current" or not. ** for performance issues , can set "current" status records '1' value , rest null value
- you don't have use 2 foreign keys , 1 - status user.
- if using hibernate post's tag :) can create view in database select "current" status records , have same structure status table.
- connect view user entity using one-to-one relation,
i hope helped !
Comments
Post a Comment