views:

422

answers:

1

I have been trying to work with DDD style for my e-commerce application. Most of my business logic are implemented using fake repositories. Now, I would like to use NHibernate to hook my Domain Model to a real database.

I have a class Order which contains a list of OrderLines object

public IList<OrderLine> OrderLines{ ... } //line 1

In my OrderLine class I have a reference to the parent Order as follows

2. public Order Order { set; get;} // line 2

According to my understanding, OrderLine is a Value class instead of an Entity class, so I will use the composite-element to do the mapping.

    <bag name="OrderLines" table="OrderLines" lazy="true">
        <key column="Order_ID"/> <!--This is where I got confused. line 3-->
        <composite-element class="OrderLine">
            <!-- class attribute required -->
            <many-to-one name="Order" class="Order" column="Order_ID"/> <!--Do I need this? line 4-->
            ...
        </composite-element>
    </bag>

Note that in line 3, I created a key element for the mapping(syntax requires this). But since I have defined a reference to Order class in my OrderLine class(line 2), do I also need to create a mapping at line 4?

A: 

You don't need line#4.

You can find a great explanation on the subject in another thread at stackoverflow here: http://stackoverflow.com/questions/766046/nhibernate-collections-and-compositeid

Martin R-L