edit: the topic of this thread was formerly "multiple sessions / refresh-problem"
but we realized, that using multiple session is not a cause for the problem.
NHibernate version: 1.0.2.0
Name and version of the database you are using: MS SQL Server 2000
Hello,
i've a problem with refreshing objets in a second session. There are two objects with a on-to-many-relation between them (the hbm-mapping-files are appended at the bottom).
In my application, i am using two sessions: One reader-session and one writer-session. The reader session is, like the name says, for reading data. There is only one reader session in the application. When i make changes to the entity objects, i am using a temporarly created session, the writer session, to persit the changes in the database.
This pattern is working well, to the point, where i have to refresh the parent-entity through the reader-session.
Here is the C# code snippet:
Code:
// gets the vather-object through the reader-session:
TestVater original = app.GetVater();
// creates a temporary writer-session:
NHibernate.ISession writerSession = m_SessionFactory.OpenSession();
// creats a 'working copy' of the object, which I want to edit:
TestVater workingCopy = writerSession.Get( original.GetType(), app.ReaderSession.GetIdentifier( original ) ) as TestVater;
workingCopy.Label = "test...";
// adds a child-entity
app.AddChild( workingCopy );
// saves the object through the writer session: (it does a Save() and a Flush())
// the changes a really saved to the database!
app.Save( writerSession, workingCopy );
// should refresh the original object through the reader session, but it doesnt work
app.Refresh( original );
// actually, it refreshes only the parent-object, exactly the "label"-property, but it doesnt refresh the
// child collection -> the newly added child is not there :(
But when I restart the application an load the parent object, the added child is there.
What should I do to bring Nhibernate to refresh the parent object AND its child-collection?
Thanks in advance,
regards kamil
------------------------
Mapping documents:(VATER means vather, KIND means child in english)
Parent entityCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-cascade="none" default-access="field.pascalcase-m-underscore">
<class name="Refresh.Test.Entities.TestVater,Refresh.Test" table="TEST_VATER" lazy="false">
<id name="VId" column="V_ID" type="Int32">
<generator class="native"/>
</id>
<property column="LABEL" type="String" name="Label" />
<bag name="TestKinder" table="TEST_KIND" lazy="false" cascade="all-delete-orphan"
outer-join="true" >
<key column="V_ID"/>
<one-to-many class="Refresh.Test.Entities.TestKind,Refresh.Test"/>
</bag>
</class>
</hibernate-mapping>
Child entityCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-cascade="none" default-access="field.pascalcase-m-underscore">
<class name="Refresh.Test.Entities.TestKind,Refresh.Test" table="TEST_KIND" lazy="false">
<id name="KId" column="K_ID" type="Int32">
<generator class="increment"/>
</id>
<many-to-one name="VId" column="V_ID" class="Refresh.Test.Entities.TestVater,Refresh.Test" not-null="true" />
<property column="LABEL" type="String" name="Label" />
</class>
</hibernate-mapping>