Anybody have any ideas? On Oct 14, 5:16 pm, Joe <[email protected]> wrote: > I'm trying to implementchangetrackingfor myaggregateroots using > Ayende's method found > athttp://ayende.com/Blog/archive/2009/06/11/nhibernate-ndash-automatic-.... > > I have 2 entities: TestProject and TestClass. > > Here are my mappings: > > <class name="TestProject"> > <id name="Id" column="ProjectId"> > <generator class="assigned" /> > </id> > <version name="Version" unsaved-value="0" /> > <property name="Name" /> > <set name="TestCases" inverse="true" cascade="all-delete-orphan"> > <key column="ProjectId" /> > <one-to-many class="TestCase" /> > </set> > </class> > > <class name="TestCase"> > <id name="Id" column="TestCaseId"> > <generator class="assigned" /> > </id> > <many-to-one name="Project" column="ProjectId" class="TestProject" > not-null="true" /> > <component name="Metadata" class="TestCaseMetadata"> > <property name="Name" /> > <property name="Author" /> > <property name="Description" /> > </component> > </class> > > When I get a TestProject already in the database, add a new TestCase > to it, and commit I get a StaleObjectStateException. > > Here's the SQL output: > > NHibernate: SELECT testprojec0_.ProjectId as ProjectId1_0_, > testprojec0_.Version as Version1_0_, testprojec0_.Name as Name1_0_ > FROM TestProject testprojec0_ WHE > RE testprojec0_.project...@p0;@p0 = 6172be05-aec6-4bdb- > b373-1b8f47dab2dd > NHibernate: SELECT testcases0_.ProjectId as ProjectId1_, > testcases0_.TestCaseId as TestCaseId1_, testcases0_.TestCaseId as > TestCaseId0_0_, testcases0_.ProjectId > as ProjectId0_0_, testcases0_.Name as Name0_0_, testcases0_.Author as > Author0_0_, testcases0_.Description as Descript5_0_0_ FROM TestCase > testcases0_ WHERE tes > tcases0_.project...@p0;@p0 = 6172be05-aec6-4bdb-b373-1b8f47dab2dd > NHibernate: SELECT testcase_.TestCaseId, testcase_.ProjectId as > ProjectId0_, testcase_.Name as Name0_, testcase_.Author as Author0_, > testcase_.Description as De > script5_0_ FROM TestCase testcase_ WHERE testcase_.testcase...@p0;@p0 > = 122d003e-9c54-4a03-b3e5-c70c3e0237e2 > NHibernate: UPDATE TestProject SET Version = @p0 WHERE ProjectId = @p1 > AND Version = @p2;@p0 = 4, @p1 = 6172be05-aec6-4bdb-b373-1b8f47dab2dd, > @p2 = 3 > NHibernate: INSERT INTO TestCase (ProjectId, Name, Author, > Description, TestCaseId) VALUES (@p0, @p1, @p2, @p3, @p4);@p0 = > 6172be05-aec6-4bdb-b373-1b8f47dab2dd, > �...@p1 = 'TC246', @p2 = 'John', @p3 = 'Test some things', @p4 = > 122d003e-9c54-4a03-b3e5-c70c3e0237e2 > NHibernate: UPDATE TestProject SET Version = @p0, Name = @p1 WHERE > ProjectId = @p2 AND Version = @p3;@p0 = 4, @p1 = 'Website', @p2 = > 6172be05-aec6-4bdb-b > 373-1b8f47dab2dd, @p3 = 3 > > The last update seems to be the problem; I don't know why it's using a > stale version number. The only way I can get things working is if I > use optimistic-lock="false" for the set in TestProject. Ayende's > example didn't seem to suffer from this problem so I'm wondering why? > > Thanks
-- 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.
