@OneToOne relationship with @JoinTable and DeletePolicy.UNLINK: bug in DeletePolicyProcessor

Suppose we have a bidirectional @OneToOne relationship mapped with @JoinTable; it’s perfectly legal since Java EE 6:

A join table is typically used in the mapping of many-to-many and unidirectional one-to-many associations. It may also be used to map bidirectional many-to-one/one-to-many associations, unidirectional many-to-one relationships, and one-to-one associations (both bidirectional and unidirectional).

@Table(name = "TEST_ENTITY")
@Entity(name = "test$Entity")
public class Entity extends BaseUuidEntity {
    // ...

    @JoinTable(name = "TEST_ENTITY_HIERARCHY",
        joinColumns = @JoinColumn(name = "PREV_ID"),
        inverseJoinColumns = @JoinColumn(name = "NEXT_ID"))
    @OnDelete(DeletePolicy.DENY)
    @OneToOne(fetch = FetchType.LAZY)
    private Entity nextEntity;

    @OneToOne(mappedBy = "nextEntity", fetch = FetchType.LAZY)
    @OnDelete(DeletePolicy.UNLINK)
    private Entity previousEntity;

    // ...
}

So far so good - the platform correctly loads and shows data. But If we try to delete such entity, DeletePolicyProcessor will simply set the “corresponding column” for previousEntity field to null (as if it was @JoinColumn mapping) - see com.haulmont.cuba.core.sys.persistence.DeletePolicyProcessor#hardSetReferenceNull method.

I didn’t check DeletePolicy.CASCADE behavior, but it seems to me that it has same issue - see com.haulmont.cuba.core.sys.persistence.DeletePolicyProcessor#hardDeleteNotLoadedReference method.

Thank you for reporting the problem.
Created issue: OneToOne relationship with @JoinTable and DeletePolicy.UNLINK · Issue #1260 · cuba-platform/cuba · GitHub