Christian Sell wrote:
Hello,
I have 2 classes that are related through a one-to-one association, which is mapped to a foreign key. I am doing a query that retreives all instances of class A. When I look at the generated SQL, I see that for each A, another statement is issued to get the related B - leading to the infamous N+1 problem with extreme amounts of SQL being generated.
Since I do not need the A->B references in my particular case, I tried to modify the mapping such that the A->B reference would be resolved lazily. However, I seem to be unable to do away with the redundant SQL, no matter what I try. I have even found a section in the docs which seems to indicate that this is not possible at all, which I would find rather shocking, and, in my case, unacceptable.
Hibernate version: 3.1.2
mapping A:
one-to-one name="b" lazy="proxy" property-ref="a"
mapping B:
many-to-one name="a" column="a_id" update="false" unique="true" not-null="true"
Query:
from A a
thanks,
Christian
do you have constrained="false" ?