|
Hello...I am relatively new to .NET, but have a lot of experience using Hibernate in the Java world (wow, I miss Java). Anyway, I have decided to try NHibernate on the project I am currently on, but have run into an issue that I simply cannot figure out.
I have a class with a mapping as follows:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="CustomCode.Model" assembly="CustomCode">
<class name="Import" table="dbo.tblImport" lazy="false">
<id name="UID" column="UID" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<discriminator column="DiscriminatorCode" type="String"/>
<property name="ImportDescription" column="ImportDescription" type="String"/>
<property name="StartDatetime" column="StartDatetime" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="EndDatetime" column="EndDatetime" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<many-to-one name="ImportType" class="CustomCode.Model.ImportType" column="ImportTypeUID"/>
<set name="ImportSourceFiles" inverse="true" lazy="false" cascade="save-update">
<key column="ImportUID"/>
<one-to-many class="ImportSourceFile"/>
</set>
<subclass name="CashFlowImport" discriminator-value="CashFlow">
<set name="CashFlows" inverse="true" lazy="false">
<key column="ImportUID"/>
<one-to-many class="CustomCode.Model.CashFlowStaging"/>
</set>
</subclass>
<subclass name="InvestorImport" discriminator-value="Investor">
<set name="Investors" inverse="true" lazy="false">
<key column="ImportUID"/>
<one-to-many class="CustomCode.Model.InvestorStaging"/>
</set>
</subclass>
</class>
</hibernate-mapping>
As you can see, the class has two subclasses defined, each of which has their own underlying Set collections. I have these collections defined to NOT be lazy.
Within my code, I create a new instance of the appropriate Import subclass and save. The underlying collections are actually saved via another process (actually by kicking off a SQL Server Integration Services job because of the complexity of the job). Thus, no cascading is being used.
Immediately after persisting both the Import object and the underlying collections to the database and committing, I re-retrieve the Import object from the database. However, when I try accessing one of the underlying collections, they are null.
I then transfer to a new page (calling Server.Transfer), and I try retrieving the Import object once again in the page's OnLoad event. Again, the collection is empty. However, I have a button on this page. When this button is clicked and the OnLoad event is triggered again, the Import object's underlying collection is populated.
This seems like some weird behavior to me. I have a feeling it has to do with my lack of knowledge of the request cycle in .NET, but I'm not sure. Any help or insight would be greatly appreciated.
|