'Any way to do one-to-one association by non primary key in spring data

I have a situation where two entities are to be joined on non-primary key column. I have following situation:

@Embeddable
Entity EmbeddedKey{
    private String apple;
    private String banana;
    private int cat;
}
@Entity
public class ParentEntity{

    @EmbeddedId
    private EmbeddedKey embeddedKey;

    @Column(name = "dog")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private BigInteger dog;

    @OneToOne(mappedBy = "parentEntity")
    @JoinColumn(name = "dog", referencedColumnName = "dog")
    private ChildEntity childEntitty;
}
@Entity
public class ChildEntity{

    @OneToOne
    @PrimaryKeyJoinColumn(name = "dog", referencedColumnName = "dog")
    private ParentEntity parentEntity;

    @Id
    @Column(name = "dog")
    private BigInteger dog;
}

When I deploy code, i get

Caused by: org.hibernate.MappingException: broken column mapping for: ParentEntity.id of: x.y.z.ChildEntity. 

As per me, hibernate is trying to join primary key of parent table with primary-key of child table which my design doesn't want. column dog is unique but not primary key due to unavoidable reason.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source