views:

44

answers:

2

I have the following map. My intention is for the order.BasketId to map to orderItem.BasketId. Tho when i look at the sql i see that it's mapping order.Id to orderItem.BasketId. How do i define in my order map which order property to map against basketId. It seems to default to the primary key.

 <class name="Order" table="Orders">
    <id name="Id" type="Int32" column="Order_ID" unsaved-value="0">
      <generator class="identity"/>
    </id>

    <property name="BasketId" column="Basket_ID" type="Int32"/>
    <set name="OrderItems" table="item_basket_contents" generic="true" inverse="true"  >
      <key column="Basket_ID" />
     <one-to-many class="EStore.Domain.Model.OrderItem, EStore.Domain"/>      
    </set>
  </class>

and orderItem

  <class name="OrderItem" table="Item_Basket_Contents">
    <id name="Id" type="Int32" column="ID" unsaved-value="0">
      <generator class="identity"/>
    </id>

    <property name="BasketId" column="Basket_ID" type="Int32"/>
  </class>
A: 

Can you change the structure? I would have a Basket entity, which contains the order items. Your order then refers to this basket, and the basket contains the items. The explicit basketID in Order is circumventing some of the ORM that hibernate does.

mdma
i've inherited this db structure which is a mess. ideally i would change it like you said, but i'm not really sure how this would the rest of the app, kinda caught in no mans land,
frosty
+1  A: 

Use the following:

<key column="Basket_ID" property-ref="BasketId" />

That's it.

Diego Mijelshon
ah, i see. thanks again :)
frosty