Hibernate Version
3.5.0.Final (with patch from
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3824)
I've been trying to map a bidirectional @OneToOne association using a @JoinColumn on a non-primary key, without much luck so far. It seems to me that the functionality is missing right now, as somebody supplied a patch to implement the functionality. Even with the patch I couldn't get it to work though. The association from HI to H is not correctly loaded from the DB and it's always null.
There are to entities H and HI associated with a bidirectional @OneToOne on the field objId and objIdHTarget respectively.
Here are the annotated POJOS:
Code:
public class H {
private String id;
private HI hiFormula;
private String objId;
private String value;
public String getObjId() {
return objId;
}
public void setObjId(String objId) {
this.objId = objId;
}
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "objId", referencedColumnName = "objIdHTarget", nullable = false, insertable = false, updatable = false, unique = false)
@ForeignKey(name = "none")
public HI getHiFormula() {
return this.hiFormula;
}
public void setHiFormula(HI hiFormula) {
this.hiFormula = hiFormula;
}
[..]
}
Code:
public class HI Serializable {
private String id;
private String objIdHTarget;
private Date valid_from;
private Date valid_until;
private String author_from;
private String author_until;
private String branch_ID;
private H h;
@OneToOne(mappedBy="hiFormula")
public H getH() {
return this.h;
}
public void setH(H h) {
this.h = h;
}
[..]
}
Here's the log file:
[url]
http://paste.ideaslabs.com/show/oV5o0Fn2qH[/url]
In the test I am simply creating a H, HI object with the matching fields and trying to load H in a different critieria and look at the getters for the association.