Optional one-to-one mapping in Hibernate

后端 未结 5 1518
旧时难觅i
旧时难觅i 2021-02-18 23:05

How do I create an optional one-to-one mapping in the hibernate hbm file? For example, suppose that I have a User and a last_visited_page table. The user may or may not have a l

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-18 23:22

    If a user has at most one last_visited page, then there are two cases :

    (a) some given user has no last_visited page, in which case there will not be any tuple for this user in the last_visited_page table, (b) some given user has exactly one last_visited page, in which case there will be exactly one tuple for this user in the last_visited_page table.

    That should make it obvious that userid is a candidate key in your last-visited-page table.

    And that should make it obvious that you should declare that key to the DBMS.

提交回复
热议问题