Hi,
Using Hibernate 3.5.6, with the following:
Code:
class A
{
@Id
private long id;
private long aUniqueId;
@OneToOne( mappedBy="a")
private B b;
}
class B
{
@Id
private long id;
private long bUniqueId;
@OneToOne
@JoinColumn( name="aId", referencedColumnName="aUniqueId" )
private A a; // column (aId) is a foreign key to A.aUniqueId
}
So to join the two tables, the join should be like:
Code:
from A a0 left outer join B b1 on a0.aUniqueId=b1.aId
However, I noticed in that the org.hibernate.type.OneToOne class for A will not actually use B's @JoinColumn but will always use A's primary key so the query incorrectly becomes:
Code:
from A a0 left outer join B b1 on a0.id=b1.aId
I got around this issue by doing the following change for A.b's annotation:
Code:
@OneToOne
@JoinColumn( name="aUniqueId", referencedColumnName="aId", insertable=false, updateable=false )
private B b;
Hibernate is converting the @OneToOne relationship into a @ManyToOne when the @JoinColumn is present. I don't mind that on B, but I do mind it on A because it does introduce an extra table join in the query:
Code:
from A a0 left outer join B b1 on a0.aUniqueId=b1.aId left outer join A a2 on b1.aId=a2.aUniqueId
I would like to use @OneToOne( mappedBy="a" ) for A. Any suggestions? Is this a bug/issue in Hibernate because the OneToOneType doesn't use the mappedBy's @JoinColumn?
thanks,
Trev