views:

19

answers:

1

Lets suppose that I have a Category table with a column that holds the id of a parent or child category from the same table. This design would allow me to have unlimited levels of Categories, or unlimited levels in a thread, for example.

How can I map this relationship with NHibernate? Are there any disadvantages or warnings that I should take into consideration when doing this?

+1  A: 

You map it as ny other many-to-one:

<class name="foo" class="mylib.fooclass">
    <id>...</id>
    ...

    <many-to-one name="ParentFoo" type="mylib.fooclass" column="parentId" />
</class>

the only warning is to take care with circular references as well as non-lazyloaded collections and properties...

Jaguar