Optional one-to-one mapping in Hibernate

后端 未结 5 1497
旧时难觅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:07

    Just spend most of the day today trying to do a similar thing, finally found the following solution (just in-case this might be useful for other people)

    @OneToOne
    @JoinColumn(name="ClassA_Id", referencedColumnName="ClassB_Id", nullable=true)
    

    Hope that might help save somebody some time

提交回复
热议问题