It appears I was doing the wrong type of mapping for this
relationship.

I got this corrected w/ the following xml config for the product
entity

<?xml version="1.0" encoding="utf-8" ?>
  <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="SampleApplication.Library.Entity.Product,
SampleApplication.Library" table="Products">
    <id name="ID" column="ID" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="ProductName" column="ProductName" type="string"
not-null="false" />
    <property name="QuantityPerUnit" column="QuantityPerUnit"
type="string" not-null="false" />
    <property name="UnitPrice" column="UnitPrice" type="decimal" not-
null="false" />
    <property name="UnitsInStock" column="UnitsInStock" type="Int32"
not-null="false" />
    <property name="UnitsOnOrder" column="UnitsOnOrder" type="Int32"
not-null="false" />
    <property name="ReorderLevel" column="ReorderLevel" type="Int32"
not-null="false" />
    <property name="Discontinued" column="Discontinued" type="boolean"
not-null="false" />
    <many-to-one name="Supplier"
class="SampleApplication.Library.Entity.Supplier,
SampleApplication.Library">
      <column name="SupplierID" sql-type="int" not-null="false"
index="ID"/>
    </many-to-one>
  </class>
</hibernate-mapping>

And the following XML config for the supplier entity

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="SampleApplication.Library.Entity.Supplier,
SampleApplication.Library" table="Suppliers">
    <id name="ID" column="ID" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="CompanyName" column="CompanyName" type="string"
not-null="false" />
    <property name="ContactName" column="ContactName" type="string"
not-null="false" />
    <property name="ContactTitle" column="ContactTitle" type="string"
not-null="false" />
    <property name="Address" column="Address" type="string" not-
null="false" />
    <property name="City" column="City" type="string" not-
null="false" />
    <property name="Region" column="Region" type="string" not-
null="false" />
    <property name="PostalCode" column="PostalCode" type="string" not-
null="false" />
    <property name="Country" column="Country" type="string" not-
null="false" />
    <property name="Phone" column="Phone" type="string" not-
null="false" />
    <property name="Fax" column="Fax" type="string" not-null="false" /
>
    <property name="HomePage" column="HomePage" type="string" not-
null="false" />
    <bag name="Products" lazy="true" generic="true" inverse="true"
cascade="all">
      <key column="SupplierID" />
      <one-to-many class="SampleApplication.Library.Entity.Product,
SampleApplication.Library"/>
    </bag>
  </class>
</hibernate-mapping>

On Aug 5, 11:44 am, toranb <[email protected]> wrote:
> The mapping below works for my product - supplier relationship in that
> it lazy loads a supplier object when I query the IList property of a
> specific product object. But I can't figure out is why the lazy
> loading does a query on the Suppliers table using the product ID
> instead of the FK (SupplierID)
>
> for example: right now product.suppliers(0).id = 1 same as the product
> id instead of 22 as it shows up in northwind (supplierid = 22)
>
> <?xml version="1.0" encoding="utf-8" ?>
>   <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
>   <class name="SampleApplication.Library.Entity.Product,
> SampleApplication.Library" table="Products">
>     <id name="ID" column="ID" type="Int32" unsaved-value="0">
>       <generator class="native" />
>     </id>
>     <property name="ProductName" column="ProductName" type="string"
> not-null="false" />
>     <property name="QuantityPerUnit" column="QuantityPerUnit"
> type="string" not-null="false" />
>     <property name="UnitPrice" column="UnitPrice" type="decimal" not-
> null="false" />
>     <property name="UnitsInStock" column="UnitsInStock" type="Int32"
> not-null="false" />
>     <property name="UnitsOnOrder" column="UnitsOnOrder" type="Int32"
> not-null="false" />
>     <property name="ReorderLevel" column="ReorderLevel" type="Int32"
> not-null="false" />
>     <property name="Discontinued" column="Discontinued" type="boolean"
> not-null="false" />
>     <bag name="Suppliers" generic="true" lazy="true" inverse="true">
>       <key column="ID" />
>       <one-to-many class="SampleApplication.Library.Entity.Supplier,
> SampleApplication.Library"/>
>     </bag>
>   </class>
> </hibernate-mapping>
>
> Keep in mind that database PK for both Products and Suppliers SQL
> tables are ID (not ProductID / SupplierID as they are w/ the default
> Northwind database)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to