Which tool generated this mapping? it looks very verbose an weird. In any case using conversations an identity won't work nice see this post where Fabio shows how identity breaks it all
http://fabiomaulo.blogspot.com/2008/12/identity-never-ending-story.html If you want create a test and put it in uNHAddins group, i will take a look at it. But you shouldn't use identity and you should be less verbose... Why did you go for the -1 thing is this a legacy DB? I think that removing the unsaved-value and using Hilo will solve the problem, there is no reason if is not a legacy system which does something weird to have 0 as a valid value for a surrogate key. Gustavo. On Mon, Feb 23, 2009 at 9:13 AM, Dcam <[email protected]> wrote: > > I've have the following hbm file: > > <?xml version="1.0" encoding="utf-8" ?> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > assembly="Proj.Core" namespace="Proj.Core.Entity"> > <class name="Unit" table="Unit" select-before-update="false" > > <id name="Id" column="UniId" type="Int16" unsaved-value="-1"> > <generator class="identity"/> > </id> > <timestamp name="UpdatedUtc" column="UniUpdatedUtc" > generated="always"/> > <property name="Enabled" column="UniEnabled" type="Boolean" > not-null="true"/> > <property name="Name" column="UniName" type="String" not- > null="true" length="30"/> > <property name="Factor" column="UniFactor" type="Double" not- > null="true"/> > </class> > </hibernate-mapping> > > I implemented my project base on Gustavo Ringel's article "uNHAddIns > Persistent Conversation" at > > http://gustavoringel.blogspot.com/2009/02/unhaddins-persistence-conversation-part_08.html > > When I try to save a new Unit object/entity with Id = -1, I get an > StaleObjectStateException with text: "Row was updated or deleted by > another transaction (or unsaved-value mapping was incorrect): > [Proj.Core.Entity.Unit#-1]". The object is saved using > Session.SaveOrUpdate. > > What is wrong with my definition or what do I have to define > differently, so NHibernate recognizes new objects/entities itself, so > I don't have to do it myself an use Session.Save for a new object? > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
