|
Hi all.
I have 2 class: Customer associate with Customers table and Order associate with Orders table in database.
I'd like to use lazy-load to load Customer without Order. just load the proxy of Order. How can i do that?
Here is mapping files:
//Customer.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NorthwindCS" assembly="NorthwindCS">
<class name="Customer" table="Customers" >
<id name ="CustomerID" column ="CustomerID" type="String" length="5">
<generator class="assigned"></generator>
</id>
<property name="CompanyName" column ="CompanyName" type ="String" length="40" not-null ="true"/>
<property name="ContactName" column="ContactName" type ="String" length="30"/>
<property name="ContactTitle" column ="ContactTitle" type ="String" length="30"/>
<property name="Address" column="Address" type ="String" length="60"/>
<property name="City" column="City" type ="String" length="15"/>
<property name="Region" column="Region" type ="String" length="15"/>
<property name="PostalCode" column="PostalCode" type ="String" length="10"/>
<property name="Country" column="Country" type ="String" length="15"/>
<property name="Phone" column="Phone" type ="String" length="24"/>
<property name="Fax" column="Fax" type ="String" length="24"/>
<bag name ="Orders" cascade ="all-delete-orphan">
<key column="CustomerID"/>
<one-to-many class ="Order"/>
</bag>
</class>
</hibernate-mapping>
// Order.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NorthwindCS" assembly="NorthwindCS">
<class name="Order" table="Orders" >
<id name="OrderID" column="OrderID">
<generator class="increment"/>
</id>
<property name="OrderDate" column="OrderDate"/>
<property name="RequiredDate" column="RequiredDate"/>
<property name="ShippedDate" column="ShippedDate"/>
<property name="Freight" column="Freight"/>
<property name="ShipName" column="ShipName"/>
<property name="ShipAddress" column="ShipAddress"/>
<property name="ShipCity" column="ShipCity"/>
<property name="ShipRegion" column="ShipRegion"/>
<property name="ShipPostalCode" column="ShipPostalCode"/>
<property name="ShipCountry" column="ShipCountry"/>
<property name="ShipVia" column="ShipVia"/>
<property name="EmployeeID" column="EmployeeID"/>
<property name="CustomerID" column="CustomerID"/>
<many-to-one name="OCustomer" class="Customer" column="CustomerID"/>
</class>
</hibernate-mapping>
when i call:
an exception was throw : Creating a proxy instance failed.
IQuery query = b.Session.CreateSQLQuery("select o.* from orders o,customers c where o.customerid =? and c.customerid=o.customerid ").AddEntity("dh", typeof(Order));
IList list = query.SetString(0, b.CustomerID).List();
return list;
_________________ JC
|