| Not sure if this helps. Same association with @JoinColumn rather than join table:
@OneToOne
@JoinColumn(name="B_FK")
private A a;
This mapping produces table A with B_FK column that is nullable. Whether I add @NotFound here or not, Hibernate will allow be to set b to null. OP mapping produces a table A2B with A_FK and B_FK both not null which act as primary key to A2B table. Hibernate will not allow to set b to null because it considers the association not nullable since both A_FK and B_FK are not nullable. It ignores the fact that @OneToOne is declared as optional. What OP did to walk around the issue is add @NotFound annotation. Combined with the commit fc7f0fca73757a5587c70854335c3b642d0e3139, this made Hibernate not throw an exception. But this is not what should have prevented Hibernate to throw an exception. That fact that @OneToOne is optional should have been enough, just like in the case where there is no join table. |