b]Hibernate version:[/b]
2.0 Alpha 1
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Monitor.Udr.Application.CustomScreens.BLL" namespace="Monitor.Udr.Application.CustomScreens.DomainModel">
<class name="Activity" table="ACACTIVITY">
<cache usage="read-only"/>
<id type="string" name="Id" column="ACTIVITY" length="15">
<generator class="assigned"/>
</id>
<set name="MilestoneSummarys">
<key column="ACTIVITY"/>
<one-to-many class="MilestoneSummary"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Monitor.Udr.Application.CustomScreens.BLL" namespace="Monitor.Udr.Application.CustomScreens.DomainModel">
<class name="MilestoneSummary" schema="dbo" table="NHACMILESTN">
<cache usage="read-only"/>
<id access="field" name="m_milestoneKey" column="MILESTONE_KEY">
<generator class="assigned"/>
</id>
<discriminator column="MILESTONE_CAT" type="String"/>
<property name="m_activityId" access="field" column="ACTIVITY"/>
<property name="m_milestoneCat" access="field" column="MILESTONE_CAT"/>
<many-to-one name="Activity" column="ACTIVITY" />
<subclass name="RevenueMilestoneSummary" discriminator-value="R"/>
<subclass name="BillingMilestoneSummary" discriminator-value="B"/>
</class>
Code between sessionFactory.openSession() and session.close():
Activity a = SessionManager.CurrentSession.Get<Activity>("2ND-BAC-CONT");
foreach (MilestoneSummary ms in a.MilestoneSummarys)
{
decimal amt = ms.Balance;
}
Name and version of the database you are using:
SQL Server 2000
I'm posting this so someone else doesn't have to spend a day trying to figure out what's wrong.
Briefly, the Id column, ACTIVITY, of the Activity class is char(15). If I get an Activity using
Activity a = SessionManager.CurrentSession.Get<Activity>("2ND-BAC-CONT");
everything appears to work, but Activity.MilestoneSummarys is empty. If I get the same Activity using
Activity a = SessionManager.CurrentSession.Get<Activity>("2ND-BAC-CONT ");
(the Id is padded out to 15 characters), the MilestoneSummarys collection is populated correctly. This behavior is at least surprising. Presumably, it's due to some confusion about the precise value of the object identity, and NHibernate is being stricter than the database.
IMO, it would be better to fail the initial Get() with the truncated key, than to have the Get() succeed but have various object relationships silently broken.
_________________ Mike Abraham
|