Thanks for helping.
I have a table Customer and a table State.
Each customer has an optional FKStateId.
My Customer class has a field of type State.
Here are the 2 mappings file:
CUSTOMER MAPPING:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Syple.Velocity.Data" namespace="Syple.Velocity.Data.Domain">
<class name="Customer" table="customer">
<id name="ID" type="int" column="PKCustomerId">
<generator class="identity"/>
</id>
<property name="FirstName" column="FirstName" type="System.String"
not-null="false" />
<property name="MiddleName" column="MiddleName"
type="System.String" not-null="false" />
<property name="LastName" column="LastName" type="System.String"
not-null="false" />
<property name="Title" column="Title" type="System.String" not-
null="false" />
<property name="BusinessPhone" column="BusinessPhone"
type="System.String" not-null="false" />
<property name="HomePhone" column="HomePhone" type="System.String"
not-null="false" />
<property name="MobilePhone" column="MobilePhone"
type="System.String" not-null="false" />
<property name="EmailAddress" column="EmailAddress"
type="System.String" not-null="false" />
<property name="UnitNumber" column="UnitNumber"
type="System.String" not-null="false" />
<property name="StreetNumber" column="StreetNumber"
type="System.String" not-null="false" />
<property name="StreetName" column="StreetName"
type="System.String" not-null="false" />
<property name="Suburb" column="Suburb" type="System.String" not-
null="false" />
<property name="Postcode" column="Postcode" type="System.String"
not-null="false" />
<property name="CurrentVehicle" column="CurrentVehicle"
type="System.String" not-null="false" />
<property name="ReceiveMarketing" column="ReceiveMarketing"
type="System.Boolean" not-null="true" />
<property name="IsCompany" column="IsCompany"
type="System.Boolean" not-null="true" />
<many-to-one name="State" column="FKStateId" class="State" />
<one-to-one name="BusinessCustomer" class="BusinessCustomer"
cascade="all-delete-orphan" />
<bag name="Enquiries" table="enquiry" inverse="true" lazy="true"
cascade="save-update">
<key column="FKCustomerId" />
<one-to-many class="Enquiry"/>
</bag>
<bag name="SalesActivities" table="salesactivity" inverse="true"
lazy="true" >
<key column="FKCustomerId" />
<one-to-many class="SalesActivity"/>
</bag>
<bag name="Notes" table="customernote" inverse="true" lazy="true"
>
<key column="FKCustomerId" />
<one-to-many class="CustomerNote"/>
</bag>
</class>
</hibernate-mapping>
STATE MAPPING:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Syple.Velocity.Data" namespace="Syple.Velocity.Data.Domain">
<class name="State" table="state" >
<id name="ID" type="int" column="PKStateId">
<generator class="assigned"/>
</id>
<property name="StateName" column="StateName"
type="System.String" not-null="true" />
<bag name="Customers" table="customer" inverse="true"
lazy="true" >
<key column="FKStateId" />
<one-to-many class="Customer"/>
</bag>
<bag name="BusinessCustomers" table="businesscustomer"
inverse="true" lazy="true" >
<key column="FKStateId" />
<one-to-many class="BusinessCustomer"/>
</bag>
</class>
</hibernate-mapping>
On Oct 20, 9:13 am, "Will Shaver" <[EMAIL PROTECTED]> wrote:
> Perhaps a bit more of the data model / mappings would be helpful here...
>
> On Sun, Oct 19, 2008 at 3:09 PM, joe <[EMAIL PROTECTED]> wrote:
>
> > Same result.
>
> > On Oct 18, 2:03 am, "Will Shaver" <[EMAIL PROTECTED]> wrote:
> >> Try .SetFetchMode(relation, FetchMode.Join);
> >> instead of Eager.
>
> >> On Thu, Oct 16, 2008 at 8:25 PM, joe <[EMAIL PROTECTED]> wrote:
>
> >> > Hi.
>
> >> > I am trying to use the criteria API to eager fetch a many to one
> >> > property.
>
> >> > ICriteria criteria =
> >> > NHibernateSession.CreateCriteria(typeof(Customer)).Add(Expression.Eq("ID",
> >> > id));
> >> > criteria.SetFetchMode("State", FetchMode.Eager);
> >> > return criteria.UniqueResult<Customer>();
>
> >> > The generated sql does do the join in order to retrieve the "State"
> >> > association property, however, my customer object's state property is
> >> > not initialized (it is not null but only the id is set).
>
> >> > Am i missing something ?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---