-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Bag of items refer by Composite Foreign Keys
PostPosted: Wed Nov 22, 2006 6:38 pm 
Newbie

Joined: Wed Nov 22, 2006 5:14 pm
Posts: 1
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:

OrderItem
Code:
<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>


TrackedItem
Code:
<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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.