These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Using SQL Server rowversion as a version column
PostPosted: Thu Sep 06, 2007 5:36 am 
Newbie

Joined: Thu Sep 06, 2007 5:06 am
Posts: 6
Hi,

It seems that SQL Server "rowversion" columns (8-byte value mapped to byte[]) cannot be used as version columns in NHibernate 1.2.0GA.

The documentation clearly states that
Quote:
Version numbers may be of type Int64, Int32, Int16, Ticks, Timestamp, or TimeSpan (or their nullable counterparts in .NET 2.0).


However, I couldn't find a way to map the SQL Server "rowversion" column to one of the supported types. When I try to map it to Int64:

Code:
<version column="RowVersion" name="RowVersion" type="Int64" generated="always"/>

The following exception is thrown:
Quote:
Unhandled Exception: NHibernate.ADOException: Could not cast the value in field
RowVersion1_0_ of type Byte[] to the Type Int64Type. Please check to make sure
that the mapping is correct and that your DataProvider supports this Data Type.


When I try to use the "correct" mapping to Byte[]:

Code:
<version column="RowVersion" name="RowVersion" type="Byte[]" generated="always"/>


I'm getting the following exception:

Quote:
System.InvalidCastException: Unable to cast object of type 'NHibernate.Type.BinaryType' to type 'NHibernate.Type.IVersionType'.
at NHibernate.Tuple.PropertyFactory.BuildVersionProperty(Property property, Boolean lazyAvailable)


I found the following closed feature ticket, "Generated properties", at JIRA:
Quote:
NHibernate should be able to use database-generated properties, including timestamps (timestamp on MySQL and SQL Server, xmin on PostgreSQL, etc.)

Looking at the code, NHibernate.Type.BinaryType does not implement NHibernate.Type.IVersionType.

Is it possible to add the needed implementation to the BinaryType class?

Thanks,
Roy.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 3:56 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
This was discussed here: http://forum.hibernate.org/viewtopic.php?t=979040. That also references another thread.

The upshot: version does not support DB generated version columns.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 11:05 pm 
Newbie

Joined: Mon Sep 17, 2007 10:30 pm
Posts: 3
Location: VIET NAM
The idea was already published on CodeProject. Here is a link:
http://www.codeproject.com/useritems/Op ... xTable.asp
Hopefully you can found the useful suggestion.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.