NHibernate version: 1.0.3.0
Hi. I have had a bit of problem with fetching child entities (
TrackedItem's) into a parent entity's (
OrderItem) bag. The child connects to the parent by a pair of foreign keys, and supposely something that is quite common (or so I thought). The schema is as follows:
Code:
------------------- ------------------
| ORDER_ITEM | 1 n | TRACKED_ITEM |
|-----------------|--------------|----------------|
| invoiceId (PK) | | Id (PK) |
| productId (PK) | | invoiceId (FK) |
------------------- | productId (FK) |
------------------
and the following xmls:
OrderItemCode:
<class name="Ra.Data.OrderItem, Ra" table="order_item">
<composite-id name="Id" class="Ra.Data.OrderItemId, Ra">
<key-many-to-one name="Invoice" column="invoiceId" class="Ra.Data.Invoice, Ra" />
<key-many-to-one name="Product" column="productId" class="Ra.Data.Product, Ra" />
</composite-id>
<bag name="TrackedItems" inverse="true" lazy="false" cascade="all">
<key>
<column name="invoiceId" not-null="true" />
<column name="productId" not-null="true" />
</key>
<one-to-many class="Ra.Data.TrackedItem, Ra" />
</bag>
</class>
TrackedItemCode:
<class name="Ra.Data.OrderItem, Ra" table="order_item">
<composite-id name="Id" class="Ra.Data.OrderItemId, Ra">
<key-many-to-one name="Invoice" column="invoiceId" class="Ra.Data.Invoice, Ra" />
<key-many-to-one name="Product" column="productId" class="Ra.Data.Product, Ra" />
</composite-id>
<bag name="TrackedItems" inverse="true" lazy="false" cascade="all">
<key>
<column name="invoiceId" not-null="true" />
<column name="productId" not-null="true" />
</key>
<one-to-many class="Ra.Data.TrackedItem, Ra" />
</bag>
</class>
I have had no problem inserting. But when I attempt to fetch, I get an empty bag.
I had a look a the log, but there were way too much information. I suspect the following lines are suggesting 5 TrackedItems were found (which is the correct number):
Code:
2006-11-22 04:25:37,518 [3072] DEBUG NHibernate.Impl.SessionImpl - attempting to resolve [TrackedItem#16]
2006-11-22 04:25:37,518 [3072] DEBUG NHibernate.Impl.SessionImpl - resolved object in session cache [Ra.Data.TrackedItem#16]
2006-11-22 04:25:37,518 [3072] DEBUG NHibernate.Loader.Loader - done processing result set (5 rows)
2006-11-22 04:25:37,518 [3072] DEBUG NHibernate.Driver.NHybridDataReader - running NHybridDataReader.Dispose()
2006-11-22 04:25:37,518 [3072] DEBUG NHibernate.Impl.BatcherImpl - Closed Reader, open Readers :0
2006-11-22 04:25:37,518 [3072] DEBUG NHibernate.Impl.BatcherImpl - Closed IDbCommand, open IDbCommands :0
2006-11-22 04:25:37,518 [3072] DEBUG NHibernate.Loader.Loader - total objects hydrated: 5
If anybody had any ideas on what I can do to get the Composite FK going, I would very much appreciate it. The problem has plagued me for days now.
I can also run NHibernate in debug mode. If somebody care to point me to where the bag populates, I can get a closer look.
Thank you.