| I think the commit in question is useful, it just does not address the underlying issue of this bug, it fixes a separate issue. As you said, @NotFound can be useful if you work with database that does not enforce foreign keys (MyISAM engine of MySQL for instance). In this context, if you know that you may have values pointing to entities that do not exist, it may be useful to ignore such values and assume the value is null. So if @NotFound implementation was not working in such a case (I didn't test, so I don't know), then the commit did fix that particular bug (although only for @OneToOne, not @ManyToOne). But as you also mentioned indirectly, @NotFound should not have been used to begin with in OP mapping because he intended to leave the association as null not assign it a value that did not exist. So the actual bug of this issue is that Hibernate threw PropertyValueException when it shouldn't have. The association is marked as optional, so Hibernate should have allowed to save it without exception. Presence of @NotFound should not affect this. The key to reproducing the bug is the presence of @JoinTable rather than @JoinColumn and not @NotFound. I can write a new test case but it would be exactly the same as OP, just either without @NotFound or switched to @ManyToOne. The commit fc7f0fca73757a5587c70854335c3b642d0e3139 unintentionally made the test pass by setting optional to true for @OneToOne mapping through presence of @NotFound, but that's just a coincidence. Personally, I would just reopen this issue and reference it in subsequent commit(s) that properly fix the bug. All posts present in this discussion will be relevant to whoever might be looking at this few years down the road. |