Given: class A (parent) and class B (child). B's id is mapped to an SQL identity column. Parent-child relationship management is relegated to a dictionary class, BMap, which is mapped as a component of A, and is indexed on B's id.
Relevant mapping sections:
Code:
<class name="A" ... >
...
<component name="Bs" class="BMap" >
<map name="map" inverse="true" cascade="all-delete-orphan" >
<key column="AID" />
<index column="ID" />
<one-to-many class="B" />
</map>
</component>
</class>
...
<class name="B" ... >
<id name="ID" type="Int32" ... >
<generator class="identity" />
</id>
...
</class>
Now suppose I add a B to an A...
Code:
ISession session ...
A ana = (A)session.Load( typeof(A), ... );
B ab = new B(...);
ana.Bs.Add(ab);
At this point, ab.ID will carry the default value and can be retrieved from ana.Bs (that is, ab == ana.Bs[ab.ID]). Now if I flush the session:
Code:
session.Flush();
everything is persisted nicely, and ab.ID is updated to the DB generated identity, but it's map index is not (so, now ana.Bs[ab.ID] == null).
Of course, this issue isn't pathalogical; the next time ana is retrieved from the DB everything is correct, but I'd rather not have to pull it up after each add in order to synchronize the index and IDs. Also, this could be compensated for within the BMap wrapper class, but that gets pretty ugly.
So: bug or feature?