zina
zina

Reputation: 258

Nhibernate - combine <join> and <bag> tags in class mapping

I need your help.

I mapped my class with <Join> tag and want to add also <bag>

something like :

  <class name="Hilan.HilanNet.Common.Pension.ClassA,Hilan.HilanNet.Common" table="ClassA_VW">
    <cache usage="read-write"/>
    <composite-id>
      <key-property name="columnA" column="sqlColumnA"/>
      <key-many-to-one name="columnB" column="sqlColumnB" class="Hilan.HilanNet.Common.Pension.ClassB, Hilan.HilanNet.Common" />
    </composite-id>
    other properties
    <join optional="true" table="AdditionalColumns_TB" inverse="false" >
      <key>
        <column name="columnA" />
        <column name="columnB"/>
      </key>
      <property name="propertyA" />
    </join>
      here I want to add the bag
    <bag
           name="Details"
           lazy="true"
           inverse="true"
           access="nosetter.camelcase-underscore"
           table="Details_VW" cascade="all">
      <cache usage="read-only"/>
      <key>
        <column name="ColumnA" />
        <column name="ColumnB"/>
      </key>
      <property name="PrincipalId" />
    </bag>
  </class>   

but I get an error -

"The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'bag' in namespace "

Why cant I do it??

Thank you !

Upvotes: 2

Views: 810

Answers (1)

Mr Mush
Mr Mush

Reputation: 1538

The element <join> needs to be the last element in <class> every element after is not recognized.

<class name="Hilan.HilanNet.Common.Pension.ClassA,Hilan.HilanNet.Common" table="ClassA_VW">
<cache usage="read-write"/>
<composite-id>
  <key-property name="columnA" column="sqlColumnA"/>
  <key-many-to-one name="columnB" column="sqlColumnB" class="Hilan.HilanNet.Common.Pension.ClassB, Hilan.HilanNet.Common" />
</composite-id>
<bag
       name="Details"
       lazy="true"
       inverse="true"
       access="nosetter.camelcase-underscore"
       table="Details_VW" cascade="all">
  <cache usage="read-only"/>
  <key>
    <column name="ColumnA" />
    <column name="ColumnB"/>
  </key>
  <property name="PrincipalId" />
</bag>
<join optional="true" table="AdditionalColumns_TB" inverse="false" >
  <key>
    <column name="columnA" />
    <column name="columnB"/>
  </key>
  <property name="propertyA" />
</join>
</class> 

Upvotes: 2

Related Questions