I too need to model a unidirectional one-to-one relation and I can’t use mappedBy (details here). Using @JoinColumn didn’t work for me either. But I must admit I’m still on 6.6 – is there anything in newer releases that’s relevant here, perhaps?
One way to handle this in my particular case would be to use a @OneToMany-relation so I can use mappedBy, and then pretend it’s OneToOne through getter/setter. Continuing the example:
@Entity
class Parent {
@OneToMany(mappedBy = "parent", cascade = ALL)
private Set<Child> children = new HashSet<Child>();
public Child getChild() {
for (Child ch : children) {
return ch;
}
return null;
}
public void setChild(Child ch) {
children = Set.of(ch);
}
}
Not too elegant, but it’ll work I presume. Anybody know of a better way?