NHibernate Pitfalls: Collections of Elements and Inverse

This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.

When mapping a collection of elements, this collection should not be marked as inverse. This is a different behavior from many to many or one to many, and it is because on the other endpoint of the relation, there is no entity to have the ownership of the relation, which is what the inverse attribute is for.

A simple example, in HBM.XML, just to remember:

   1: <class name="Post" lazy="true" table="`POST`">
   2:     <!-- ... -->
   3:     <set cascade="all" lazy="false" name="Tags" table="`TAG`" order-by="`TAG`">
   4:         <key column="`POST_ID`" />
   5:         <element column="`TAG`" type="String" length="20" not-null="true" unique="true" />
   6:     </set>
   7:     </class>
   8: </hibernate-mapping>


1 Comment

Comments have been disabled for this content.