nhibernate bidirectional one-to-one using bags

112 views
Skip to first unread message

Ricardo Peres

unread,
May 13, 2013, 1:28:45 PM5/13/13
to nhu...@googlegroups.com
Shouldn't the bags be marked as inverse?

RP

Ricardo Peres

unread,
May 14, 2013, 11:31:47 AM5/14/13
to nhu...@googlegroups.com
Just add lazy=proxy or lazy=no-proxy to the one-to-one declaration.
The whole class must be lazy and the the properties must be virtual.

RP

On Tuesday, May 14, 2013 1:41:10 PM UTC+1, Stefan wrote:
Hi ,

Thank you for your suggestion. You example is not "lazy-loaded". NHibernate will issue an outer join query from LOT to LOT_INDICATEUR when you access a property of LOT. This is not what i want. I want a select for LOT_INDICATEUR to be issue ONLY when i am accesing that property from LOT.

Regards

On Tuesday, May 14, 2013 3:54:24 AM UTC-5, Frédéric Delaporte wrote:
Hello,
I do not understand why do you need to map your one-to-one through bags for "performance consideration". I have a classical one-to-one with one end nullable, with lazy-loading enabled. And it works fine, even when the nullable end is null. (Batching seems not to be implemented on one-to-one though, I see separated queries for lazy-loading on each access.)

Here is the mapping (xml, I do not known the "by code" syntax) I have for that :
"master table" (responsible for the primary key) :
<class name="Lot" table="LOT" mutable="false" batch-size="20">
<cache usage="read-only" />
<id name="Id" column="REF_LOT">
<generator class="identity"/> <!-- or whatever you want but not foreign -->
</id>

<!-- misc stuff ... -->

<one-to-one name="Indicateurs" class="LotIndicateur" />

<!-- misc stuff ... -->
</class>

"child table" (having its primary key foreign from "master") :
<class name="LotIndicateur" table="LOT_INDICATEUR" mutable="true" batch-size="20">
<id name="Id" column="REF_LOT">
<generator class="foreign">
<param name="property">Lot</param>
</generator>
</id>
<one-to-one name="Lot" class="Lot" constrained="true" />

<!-- misc stuff ... -->
</class>

Le lundi 13 mai 2013 16:54:50 UTC+2, Stefan a écrit :

I am trying to map a legacy bidirectional one-to-one with shared PK using 2 bags. One end of the relation can be null.

The reason i am doing this is for performance consideration (mostly to provide lazy-loading). I have tried doing this with many-to-one but i get all kind of strange issues plus i always need to check for an invalid proxy due to the possibility that there is no associated record in one end of the relation.


Reply all
Reply to author
Forward
0 new messages