I have this class
Worker
{
Guid _id;
String _Name;
Worker _boss;
//Public properties, constructor, etc...
}
Mapped to this table:
Workers
id:Guid
name:String
id_boss:Guid
And a select worker.xml similar to:
<parameterMaps>
<parameterMap id="pmAllFields" class="Worker">
<parameter property="Boss.Id" dbType="Guid"
column="id_boss" />
<parameter property="Name" dbType="VarWChar" />
<parameter property="Id" dbType="Guid" />
</parameterMap>
</parameterMaps>
<resultMaps>
<resultMap id="rmAllFields" class="Worker" >
<result property="Id" dbType="Guid" column="id" />
<result property="Boss" dbType="Guid"
column="id_boss"select="LoadAllFieldsById"/>
<result property="Name" dbType="VarWChar" column="name"
/>
</resultMap>
</resultMaps>
<statements>
<select id="LoadAllFieldsById" parameterClass="Guid"
resultMap="rmAllFields"
resultClass="Worker"
listClass="WorkerCollection"
cacheModel="none">
SELECT id, id_boss, [name]
FROM Workers
<dynamic prepend="WHERE">
<isParameterPresent>
Id = #value#
</isParameterPresent>
</dynamic>
</select>
But if I try to load a Worker that his boss is him, i get a infinite
bucle.
Ej
Id: {813CD836-9EB1-4AD5-8201-DA922105B9A9}
Id_boss: {813CD836-9EB1-4AD5-8201-DA922105B9A9}
Name: "autonomo"
Solutions i Tried:
A) Activate a cache. Not work because the worker are not insert
into cache until all his properties are loaded (included Boss
property).
<cacheModels>
<cacheModel id="none" implementation="MEMORY">
<flushInterval minutes="10"></flushInterval>
<flushOnExecute
statement="InsertAllFields"></flushOnExecute>
<flushOnExecute
statement="UpdateAllFields"></flushOnExecute>
<flushOnExecute
statement="DeleteAllFields"></flushOnExecute>
<property name="Type" value="Weak"></property>
</cacheModel>
Also i have other question.... Ibatis implements in some way
"Identity Map"
http://www.martinfowler.com/eaaCatalog/identityMap.html
I tried to simulate with the cacheModel id="none" but i don't
kwow
when and how to clear this cache.
When: When a session start ?¿
How: There is some method to clear a specific id cache
content ?
B) Activate LazyLoad for Boss property but reviewing the code i saw
that
this feature only work for collections.
I belibe this approach is the fitnes but i need to know if this
feautre
will be implement in short time.
C) Use JOIN, I tried to discard this solution because of the overhead
with
too SQL and Xml mappings Typing ;-).
Sorry for my English grammar
David Marzo