Hi guys.
I have been browsing this forum, the HB documentation and the HB in action book for a while now and I cannot figure out why ManyToOne optional associations can LAZY-load and OneToOne optional associations cannot.
Yes, I know, I have been visiting the HB wiki as well: Proxying an optional OneToOne association does not make sense since we need to know if it is null or not first and while determining that, why not load the row at the same time.
Yes, same answer in HB in Action on page 566 (FAQ: Does lazy loading of one-to-one associations work?).
But, why an optional ManyToOne association can perform lazy loading then? To me, the same logic than optional OneToOne associations should have been applied to optional ManyToOne associations. What am I missing? Where am I wrong in my assumption?
Nowhere I have been able to find an answer, nowhere the book or HB documentation says the same thing should or should not apply to ManyToOne - while they have the same fundamental problem of a single association being optional.
So I tried and tried things. This thing below will lazy load (i.e. no select is made agains the DB as long as I stick to Ref.id):
@ManyToOne(fetch=FetchType.LAZY, optional=true)
@JoinColumns({
@JoinColumn(name="REF_ID", referencedColumnName="REF_ID")
})
public Ref getRef() {
return this.ref;
}
While this property, on the same parent class: will never lazy load:
@OneToOne(fetch=FetchType.LAZY)
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name="PRT_NRI", referencedColumnName="PRT_NRI")
})
public Agent getAgent() {
return this.agent;
}
I am looking for a quick definitive answer to that! Thanks in advance.
|