Hi,

I have a problem when calling session.isDirty().

I have 2 classes: Person & Children. Here is a sample XML mapping
file:

<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="test7.Entities.Person, test7" table="persons">
        <id name="Id" column="id">
            <generator class="native" />
        </id>
        <set name="Children" cascade="all-delete-orphan" inverse="true"
lazy="true">
                        <key column="persons_id"/>
                        <one-to-many class="test7.Entities.Child, test7"/>
                </set>
    </class>
</hibernate-mapping>

Person contains a set of Child called Children

I add a Child with the following code:

Person p = session.Get<Person>(1);
Child c = new Child();
c.Parent = p;
p.Children.Add(c);

In my application, if the user closes the form, I want to warn him if
there is some unsaved data on the form.
To do so, I call session.isDirty(). If the user says he wants to save
the data, I call session.SaveOrUpdate(p).

But, when I call session.isDirty(), I see in my log that NHibernate
inserts the child in the DB (an INSERT query is performed), then it
returns TRUE (for session.isDirty()). How can I prevent it to perform
that query? Because, if the user doesn't want to save the unsaved
data, the child doesn't have to be inserted.

This behavior only happens if I add a Child to the Person. If I modify/
delete any Child of the Person or I modify the Person, all queries are
performed when I call session.SaveOrUpdate(p), not because of
session.isDirty().

Thanks for your help,

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