Good day,
I'm having a strange occurence with the ID of a class.
Hibernate version: 1.0.2
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Competition.Business.CompetitionEntrySlot, Competition.Business" table="t_rel_registration_type" lazy="true">
<cache usage="nonstrict-read-write"/>
<id name="ID" column="SlotID" type="int" unsaved-value="0">
<generator class="native" />
</id>
<many-to-one name="Entry" column="EntryID"/>
<many-to-one name="Registration" column="RegistrationID"/>
<many-to-one name="SlotType" column="TypeID"/>
</class>
</hibernate-mapping>
I have a repeater that I bind using the the following code
Code:
dlEditSlots.DataSource = Entry.Slots;
dlEditSlots.Databind();
The .Slots property is an ISet of the type that is declared above in the mapping. A simple many-to-one as shown here:
Code:
<set name="Slots" table="t_rel_registration_type" inverse="true" cascade="all-delete-orphan" lazy="true" sort="Competition.Business.SlotSequenceComparator, Competition.Business" >
<key column="EntryID"/>
<one-to-many class="Competition.Business.CompetitionEntrySlot, Competition.Business"/>
</set>
In the repeater, I have a control that shows the ID of the Slot. It all works fine the first time the repeater is bound. Subsequent binds however report the ID as being 0. (While I hate to say 'when it is bound the first time', I haven't found any other way to frame the problem). But the wierd thing is (to me at least) that the other properties of the objects are resolving perfectly fine! For example I display other properties like SlotType.Name, etc. The only difference I can see between which properties are causing problem is that the ID is the only property native to the CompetitionEntrySlot class, but I'll come back to this later.
Suspecting some proxy issues with the reflection the Repeater control might be using, I've tried to force the initialization of the ISet. To no avail, IsInitialized return true.
I tried iterating throught the ISet and trace the IDs, which caused the problem to dissapear (subsequent binds would work fine and display the proper ID instead of 0). (using a foreach() Trace.Write( o.ID ); )
With the debugger, I inspected the ISet before it gets bound. Well, each item in the set was a proxy class. The proxy was reporting a 0 as the ID (when looking at the base class of the proxy). Looking at the __interceptor property of the proxy and drilling from there, I can see that it consider itself initialized indeed (IsUninitialized = false) and that the Identifier property holds the proper ID of my class!
Basically, I'm completely lost. I'd like to understand why this is happening, but I'll settle on a solution to fix my problem other than forcibly iterating throught the Set before binding it.
Thanks for any help,
Alain-Daniel[/code]