If the @JoinColumn is part of an @EmbeddedId, and as such is non-nullable, you can’t expect to have correct results when updating the association. Since the information about which EntityB is associated with an EntityA is stored in that column, Hibernate needs to be able to set it to null to signify that no associated entity is present. The correct way to map this, if you really want to keep the foreign key as part of the composite EntityB id, would be something like this:
@Embeddable
static class EmbeddedKey implements Serializable {
@ManyToOne
@JoinColumn( name = "entityaid" )
private EntityA entityA;
@Column( name = "type", updatable = false )
private Integer type;
}
And then using mappedBy="id.entityA" on the EntityA association side. A simpler way forward would be decoupling the join column from EntityB’s identifier. |