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?

  1. 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
    1. you don't have use 2 foreign keys , 1 - status user.
    2. if using hibernate post's tag :) can create view in database select "current" status records , have same structure status table.
    3. connect view user entity using one-to-one relation,

i hope helped !


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -