﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>JesenkoS commented on NHibernate Mapping - Concurrency</title><description>To those having issue getting SQL timestamps to work,
  
if you are using NHibernate.Mapping.Attributes, [Column(...)] attribute is ignored under [Version] attribute. Workaround is to use [RawXml] to specify appropriate mapping.
  
  
Not sure whether it was already fixed in latest versions of NHibernate.Mapping.Attributes though.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment26</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment26</guid><pubDate>Fri, 12 Jun 2009 09:14:46 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>Gary, 
  
Try using generate="always"
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment25</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment25</guid><pubDate>Wed, 13 May 2009 16:10:39 GMT</pubDate></item><item><title>Gary  commented on NHibernate Mapping - Concurrency</title><description>Is it possible to use dynamic insert /update with versioning?  I'm trying to do this with Oracle and when I update a column, the generated SQL tries to update the version column (ORA_ROWSCN).  I have seen a post on stackoverflow that says the same thing happens with SQL Server timestamps.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment24</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment24</guid><pubDate>Wed, 13 May 2009 14:31:41 GMT</pubDate></item><item><title>Jimit Ndiaye commented on NHibernate Mapping - Concurrency</title><description>I using NH 2.1 Alpha2. I posted to nhusers and, getting no response, tried stackoverflow and finally your blog.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment23</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment23</guid><pubDate>Tue, 28 Apr 2009 09:44:01 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>Jimit,
  
Please use NH Users for that, and take into account that I am using the latest NHibernate
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment22</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment22</guid><pubDate>Mon, 27 Apr 2009 13:11:30 GMT</pubDate></item><item><title>Jimit Ndiaye commented on NHibernate Mapping - Concurrency</title><description>Sorry about that... it seems my version mapping got swallowed by the ether:
  
  
&lt;version  
&lt;column  
&gt;  
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment21</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment21</guid><pubDate>Mon, 27 Apr 2009 13:06:12 GMT</pubDate></item><item><title>Jimit Ndiaye commented on NHibernate Mapping - Concurrency</title><description>This is my version mapping: 
  
&lt;version  
unsaved-value="null"&gt;
  
&lt;column  
&gt;  
As you can see, it's identical to what you have above. Are you using yours together with a custom IUserVersionType? I thought binary blob implemented IVersionType.
  
  
It seems that for some reason, NHibernate is interpreting the Version property as dirty immediately after reading it from the database and thus attempts to do an update.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment20</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment20</guid><pubDate>Mon, 27 Apr 2009 13:01:05 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>Jimit,
  
You need to use sql-type="timestamp", as shown in the post
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment19</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment19</guid><pubDate>Sun, 26 Apr 2009 07:44:40 GMT</pubDate></item><item><title>Jimit Ndiaye commented on NHibernate Mapping - Concurrency</title><description>Hi,
  
Thanks for this post. It's saved me a lot of headache trying to get NHibernate to play nice with MS SQL Server's timestamp data type. Unfortunately it's created new ones. While I'm now able to use SchemaExport to create my database as I want it, saving entities to the database is proving difficult as NHibernate keeps trying to update the version column which is impossible with SQL Server. I've got a question on stackoverflow describing the situation. I'd appreciate any light you could shed on it:
  
[stackoverflow.com/.../776802#776802](http://stackoverflow.com/questions/775208/nhibernate-and-sql-timestamp-columns-as-version/776802#776802)  
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment18</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment18</guid><pubDate>Sat, 25 Apr 2009 18:27:59 GMT</pubDate></item><item><title>Marc commented on NHibernate Mapping - Concurrency</title><description>Ok, I could figure it out for myself.
  
  
Problem was that the version number of my entity was set to 0 and I didn't explicitely specify a "unsaved-value" which by default also was 0. Thus, NHibernate was quite right to try an insert. My fault.
  
  
Thx,
  
Marc
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment17</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment17</guid><pubDate>Mon, 20 Apr 2009 11:08:24 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>Please use nhusers for support, I can't figure out what the problem is.
  
When you post to nhusers, please include code + mapping
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment16</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment16</guid><pubDate>Mon, 20 Apr 2009 10:59:39 GMT</pubDate></item><item><title>Marc commented on NHibernate Mapping - Concurrency</title><description>Hmm,
  
  
having added the version-tag now in the right place, I get a database error when saving a loaded object.
  
I manually do a saveOrUpdate on a referenced child object (a localized text entity), but having configured the version-tag for each entity (the parent and the child) the saveOrUpdate now does an insert and causes a unique key constraint violation.
  
I don't know, why there is this insert statement now. Either I would expect an update or a delete and a following insert. In the latter case, the insert should work because the old row with the same unique key should have been deleted.
  
  
What am i missing? How does the version affect the saveOrUpdate() method? I thought, it would just check the value of the version column and increment it upon update (if not stale).
  
  
Thanks in advance,
  
Marc
  
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment15</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment15</guid><pubDate>Mon, 20 Apr 2009 10:44:29 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>Marc,
  
The location of the version is important, it should be just after it id.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment14</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment14</guid><pubDate>Fri, 17 Apr 2009 08:09:07 GMT</pubDate></item><item><title>Marc commented on NHibernate Mapping - Concurrency</title><description>Hi,
  
  
thanks for this nice article.
  
  
But I'm a little confused. Also having read the NHibernate docs, I tried to use the version-element in my mapping, but its not in the schema of the version I use, which is "urn:nhibernate-mapping-2.2"/ NHibernate 2.0.1.
  
  
Are the docs not in sync with the software or am I missing sth.???
  
  
Thanks,
  
Marc
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment13</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment13</guid><pubDate>Fri, 17 Apr 2009 08:03:40 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>Milton,
  
If that is the case, you need to do this yourself.
  
You can extend NHibernate to do just that , by using the listeners architecture.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment12</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment12</guid><pubDate>Thu, 16 Apr 2009 22:36:08 GMT</pubDate></item><item><title>Milton Pividori commented on NHibernate Mapping - Concurrency</title><description>What if I want to save the history of the changes? So, instead of update the row, I want to insert a new row with the new data and version. NHibernate, I think, should check (like you showed in the post) that the row with the higher version (the last inserted) is 'version - 1'.
  
  
Thank you very much for this serie of posts. It's helping me a lot.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment11</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment11</guid><pubDate>Thu, 16 Apr 2009 17:24:43 GMT</pubDate></item><item><title>David Cumps commented on NHibernate Mapping - Concurrency</title><description>I guess I'll have an elaborate look at the way NHibernate works with it's first and second level cache and how session work in detail.
  
  
It just confused me a bit I have to first go fetch something from the database before deleting it. (since in SQL you can just DELETE WHERE... and it doesn't matter if it's there or not)
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment10</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment10</guid><pubDate>Thu, 16 Apr 2009 13:11:12 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>David,
  
What you are doing is a pretty nasty trick, and as a matter of fact, it probably would stop working at some point.
  
The problem is that what you are doing circumvent the cascade and delete behavior that NHibernate has.
  
Consider it a bug that it works.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment9</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment9</guid><pubDate>Thu, 16 Apr 2009 12:38:00 GMT</pubDate></item><item><title>David Cumps commented on NHibernate Mapping - Concurrency</title><description>(Also, for some reason unsaved-value="undefined" doesn't do the trick, which I thought was the idea behind undefined, to default back to my Id columns)
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment8</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment8</guid><pubDate>Thu, 16 Apr 2009 10:16:03 GMT</pubDate></item><item><title>David Cumps commented on NHibernate Mapping - Concurrency</title><description>I tried to implement optimistic locking using the timestamp column today, but I'm having some trouble with deletes.
  
  
Before optimistic locking, I was able to simply create a new POCO object, with only the id properties filled in and then call session.Delete(theObject) and NHibernate would perform a simple "DELETE FROM .... WHERE Id = ...."
  
  
With optimistic locking enabled however, NHibernate refuses to perform a delete. It seems to only delete when I populate the Version property, but then does a "DELETE FROM ... WHERE id = ..... AND Version = ....", which ofcourse still doesn't delete me line (since I don't know the version)
  
  
Is there a way to simply delete an item regardless of whatever version is present in the database? (I wish to avoid having to roundtrip to first SELECT the object, then delete it, and doing that in a while loop in case of optimistic locking changes between the select and delete)
  
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment7</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment7</guid><pubDate>Thu, 16 Apr 2009 10:13:04 GMT</pubDate></item><item><title>Dermot commented on NHibernate Mapping - Concurrency</title><description>Jose,
  
don't rely on the documentation for an in depth understanding of NHibernate get the book Nhibernate in action.  
[www.amazon.co.uk/.../ref=sr_1_1](http://www.amazon.co.uk/NHibernate-Action-Pierre-Kuate/dp/1932394923/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1239806652&amp;sr=8-1)</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment6</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment6</guid><pubDate>Wed, 15 Apr 2009 14:46:35 GMT</pubDate></item><item><title>Jose commented on NHibernate Mapping - Concurrency</title><description>Thanks for this series of post. This is much betther than the nhibernate documentation.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment5</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment5</guid><pubDate>Wed, 15 Apr 2009 12:06:50 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>Roger,
  
You can say that, yes, but there is a distinct difference in the behavior of optimistic vs. version.
  
optimistic can work only on the changed fields, version always work on the full row version
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment4</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment4</guid><pubDate>Wed, 15 Apr 2009 09:59:58 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate Mapping - Concurrency</title><description>G.O,
  
That is just how it is shown in the profiler. The database gets the actual timestamp value, which is binary.
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment3</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment3</guid><pubDate>Wed, 15 Apr 2009 09:58:55 GMT</pubDate></item><item><title>Roger commented on NHibernate Mapping - Concurrency</title><description>To me, there are not four but three concurrency models - optimistic, pessimistic and none. "Versioned" is just an impl detail of opt concurrency.
  
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment2</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment2</guid><pubDate>Wed, 15 Apr 2009 07:53:44 GMT</pubDate></item><item><title>G.O commented on NHibernate Mapping - Concurrency</title><description>Dude, that example with the SQL timestamp didn't work out very well ("Version='System.Byte[]')
</description><link>http://ayende.com/3946/nhibernate-mapping-concurrency#comment1</link><guid>http://ayende.com/3946/nhibernate-mapping-concurrency#comment1</guid><pubDate>Wed, 15 Apr 2009 07:49:41 GMT</pubDate></item></channel></rss>