| Sorry to bring back a closed issue, but I have reason to believe that the applied fix is not complete. I just experienced the same error with @ManyToOne mapping and the commit in question only fixes @OneToOne mappings. Moreover, after debugging Hibernate internal, I believe that the underlying cause is not the fact that @NotFound annotation is not considered but the fact that Nullability check does not respect optional=true attribute on @OneToOne and @ManyToOne. Nullability check verifies that org.hibernate.mapping.Property corresponding to the association isOptional. However, nowhere in Hibernate code is this value set to true when @ManyToOne or @OneToOne has optional=true. In a regular case, where the join column is in the same table, isOptional of Property will still return true because the join column will be nullable. However, when there is a JoinTable where join column and inverse join column both act as primary key and are both not null, isOptional on the property will return false making Nullability check fail. In my opinion, the proper fix for this bug is to set org.hibernate.mapping.Property.optional field to true when the annotation specifies that the association is optional (which is JPA default). Using @NotFound in this mapping is a walkaround in the first place because whether it is set to IGNORE or EXCEPTION, Hibernate should not have thrown anything as the association is optional. Also, if you agree with this reasoning and decide to fix it, is it possible to backport the fix to Hibernate 5.1. Thank you. |