I can't get any of my one-to-one mappings that are foreign keys with a unique constraint to lazily initialize. These are mostly situations where the referenced object can be null.
Here is an example mapping for the classes customer and spouse. A customer may or may not have a spouse but if the customer does there is only one:
From the Customer mapping:
Code:
<one-to-one name="spouse" class="Spouse" property-ref="customer" cascade="all" access="field" lazy="proxy"/>
From the Spouse mapping:
Code:
<many-to-one name="customer" class="Customer" unique="true"
access="field" not-null="true" column="customer_id" cascade="none" lazy="proxy"/>
Every time I get the customer it loads the spouse if there is one. This creates a pretty significant performance hit if i load a bunch of customers at once. I have experimented with the lazy setting and the constrained="true" setting and neither seem to have an effect.
Thanks