Optional one-to-one mapping in Hibernate

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

    I was having a simliar problem, but using annotations. Google brought me here, so if anyone else finds themselves in the same sitatuions, this worked for me:

    http://opensource.atlassian.com/projects/hibernate/browse/ANN-725

    If you're using annotations, you can use the @NotFound(action=NotFoundAction.IGNORE) annotation so that you don't get an exception. Just make sure your code checks for nulls because it's now might not be there ;-)

提交回复
热议问题