c# - NHibernate Save, Delete, Save yields unique key violation -


I have a scenario where I need to do the following in the transaction: 1. A model with a unique key 2 Save to Remove that model 3. Save the first one with an new model with the same unique key.

I hope this works just fine, but a unique key violation to me

The NH profiler also shows that the removal statement was not released before inserting the second is.

My mapping looks as follows:

 & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Hibernate-Mapping XMLNS = "Color: Nurbinet-Mapping2.2" Assembly = "NHTist" & gt; & Lt; Class name = "UniqueKeyModel" table = "UniqueKeyModels" & gt; & Lt; ID name = "id" & gt; & Lt; Generator class = "heilo" /> & Lt; / Id & gt; & Lt; Property Name = "TheVal" Unique-Key = "Valuation" Type = "System.String" & gt; & Lt; / Property & gt; & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt; 

My model:

 Public class UniqueKeyModel {public virtual long id {get; Private set; } Public virtual string TheVal {get; Set; }} 

My Testcases:

Eesation Assus = ...; Unicode model mFirst = new UNIX modell {TheVal = "value"}; Sess.Save (mFirst); Sess.Delete (mFirst); Unicode modal mSecond = new uniquelymodel {TheVal = "value"}; Sess.Save (mSecond);

I think the session should be flushed after you delete. When you flush a session, the changes are written to the database. (If you are using a transaction then you have to start a new session after the session is silenced)


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -