Hi,
I am not sure what you mean that it should probably be handled inside
the person class.  By updating a person with new addresses, isn't that
the case?

As for the mapping files, first is the Person mapping

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class
name="BusinessEntities.Wellness.Person,BusinessEntities.Wellness"
table="Person" lazy="true" dynamic-insert="true" dynamic-
update="false">
    <id name="Personid" column="PersonID" type="int">
      <generator class="native" />
    </id>
    <version type="binary" generated="always" name="RecordVersion"
column="`RecordVersion`" />
    <property type="int" not-null="true" name="Customerid"
column="`CustomerID`" />
    <property type="AnsiString" not-null="true" length="9" name="Ssn"
column="`SSN`" />
    <property type="AnsiString" not-null="true" length="30"
name="FirstName" column="`FirstName`" />
    <property type="AnsiString" not-null="true" length="35"
name="LastName" column="`LastName`" />
    <property type="AnsiString" length="1" name="MiddleInitial"
column="`MiddleInitial`" />
    <property type="DateTime" name="DateOfBirth"
column="`DateOfBirth`" />
    <bag name="PersonDemogAddresses" inverse="true" lazy="true"
cascade="all">
      <key column="PersonID" />
      <one-to-many
class="BusinessEntities.Wellness.PersonDemogAddress,BusinessEntities.Wellness" /
>
    </bag>
  </class>
</hibernate-mapping>

followed by the Address mapping

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class
name="BusinessEntities.Wellness.PersonDemogAddress,BusinessEntities.Wellness"
table="PersonDemogAddress" lazy="true" dynamic-insert="true" dynamic-
update="false">
    <id name="PersonDemogAddressId" column="PersonDemogAddressID"
type="int">
      <generator class="native" />
    </id>
    <version type="binary" generated="always" name="RecordVersion"
column="`RecordVersion`" />
    <property type="AnsiString" not-null="true" length="1"
name="AddressTypeid" column="`AddressTypeID`" />
    <property type="AnsiString" not-null="true" length="60"
name="AddressLine1" column="`AddressLine1`" />
    <property type="AnsiString" length="60" name="AddressLine2"
column="`AddressLine2`" />
    <property type="AnsiString" length="60" name="City"
column="`City`" />
    <property type="AnsiString" length="2" name="UsStateId"
column="`USStateID`" />
    <property type="AnsiString" length="5" name="UsPostalCodeId"
column="`USPostalCodeID`" />
    <many-to-one name="Person" cascade="none" column="PersonID" />
  </class>
</hibernate-mapping>

On May 23, 3:45 pm, Oskar Berggren <[email protected]> wrote:
> 2010/5/21 BZaino <[email protected]>:
>
>
>
>
>
> > Hi,
> > I have a parent child relationship between a Person object and and
> > Address object.  The Person object exists in the DB.  After doing a
> > Get on the Person, I add a new Address object to the Address sub-
> > object list of the parent, and do some other updates to the Person
> > object.  Finally, I do an Update on the Person object.  With a SQL
> > trace window, I can see the update to the Person object to the Person
> > table and the Insert of the Address record to the Address table.  The
> > issue is that, after the update is performed, the AddressId (primary
> > key on the Address object) is still set to  0, which is what it
> > defaults to when you first initialize the Address object.  I have
> > verified that when I do an Add, this value is set correctly.  Is this
> > a known issue when trying to add sub-objects as part of an NHibernate
> > UPDATE?  Sample code is below
>
> > Thanks
>
> >            Person newPerson = new Person();
> >            newPerson.PersonName = "John Doe";
> >            newPerson.SSN = "111111111";
> >            newPerson.CreatedBy = "RJC";
> >            newPerson.CreatedDate = DateTime.Today;
> >            personDao.AddPerson(newPerson);
>
> >            Person updatePerson =
> > personDao.GetPerson(newPerson.PersonId);
>
> >            updatePerson.PersonAddresses = new List<PersonAddress>();
>
> Should probably be handled inside Person class.
>
> >            PersonAddress addr = new PersonAddress();
> >            addr.AddressLine1 = "1 Main St";
> >            addr.City = "Boston";
> >            addr.State = "MA";
> >            addr.Zip = "12345";
> >            updatePerson.PersonAddresses.Add(addr);
>
> >            personDao.UpdatePerson(updatePerson);
>
> Why? Is the dao closing the ISession and returning detached entities?
>
> >            int addressID = updatePerson.PersonAddresses[0].AddressId;
>
> Mappings for Person and PersonAddress?
>
> /Oskar
>
> --
> 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 
> athttp://groups.google.com/group/nhusers?hl=en.

-- 
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