views:

20

answers:

0

I have a mapping that work to retrieve all sales order headers and their sales order lines in a IList:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping ...>
  <class name="salesH" table="SalesHeader" lazy="false">
    <id name="No" column="No_" type="string"></id>
    <property name="OrderDate" column="OrderDate" type="DateTime" />
    <property name="Customer" column="CustomerNo" type="string" />
    <bag name ="Line" lazy="true" inverse="true">
      <key>
        <column name="DocumentNo"/>
      </key>
      <one-to-many class="salesL" not-found="ignore"/>
    </bag>
  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping ..>
  <class name="salesL" table="SalesLine" lazy="false">
      <composite-id >
      <key-property name="DocumentNo" column="DocumentNo" type="string" />
      <key-property name="Line" column="LineNo" type="Int32"/>
    </composite-id>
    <property name="Item" column="No_" type="string" />
    <property name="Qty" column="Quantity" type="decimal" />  </class>
</hibernate-mapping>

This is ok but I need to obtain all these data starting from salesL: now I be able to retrieve a SalesH of a line with a many-to-one association:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping ...>
  <class name="salesFlat" table="SalesLine" lazy="false">
       <composite-id >
      <key-property name="DocumentNo" column="DocumentNo" type="string" />
      <key-property name="Line" column="LineNo" type="Int32"/>
    </composite-id>
        <property name="Item" column="No_" type="string" />
    <property name="Qty" column="Quantity" type="decimal" />
    <many-to-one name="SalesH" class="salesH" column="DocumentNo"/>
  </class>
</hibernate-mapping>

This works, but to access at the property of SalesH I must write salesFlat.Item(0).SalesH.Custome . This is not a big problem but I prefer to have all property form 2 tables in the same class to access them with: salesFlat.Item(0).DocumentNo and salesFlat.Item(0).Custome .

Is there a way to accomplish this?

Thanks.

PS: When I try to use a join mapping like this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping ...>
  <class name="salesFlat" table="SalesLine" lazy="false">
    <composite-id >
      <key-property name="DocumentNo" column="DocumentNo" type="string" />
      <key-property name="Line" column="LineNo" type="Int32"/>
    </composite-id>

    <property name="Item" column="No" type="string" />
    <property name="Qty" column="Quantity" type="decimal" />

    <join table="Sales Header" >
      <key column="DocumentNo"/>
      <property name="Customex" column="Customer" type="string" />
    </join>
  </class>
</hibernate-mapping>

I obtain an exception:

NHibernate.FKUnmatchingColumnsException: Foreign key (FKD74AF707CE7245B:[SalesHeader] [[Document No_]])) must have same number of columns as the referenced primary key ([SalesLine] [[Document No_], [Line No_]])

This is probably caused by the composite-id but I can't change it bacause is in a legacy database.