-->
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.  [ 4 posts ] 
Author Message
 Post subject: Timestamp column mapping in SQL2005?
PostPosted: Fri Nov 10, 2006 8:49 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
Hello group,

I'm standing in front of a wall and banging my head. I have a timestamp column in a table in a SQL2005 database (not sure whether there's a difference to SQL2000). I should also mention that I'm using NHibernate.Mapping.Attributes rather than plain mapping files.

Now I'd like to use either the <version> or <timestamp> mapping to expose that value as a property, ideally using DateTime so I can check the last modification date e.g. for geting all objects that changed during the past 24 hours.

Here's the most recent thing I tried:
---------------------------------
Code:
Guid m_ID = Guid.Empty;
int m_LastModification = 0;

[Id(0, Name = "ID", Column = "ID", TypeType = typeof(Guid), UnsavedValue = "00000000-0000-0000-0000-000000000000")]
[Generator(1, Class = "guid.comb")]
[Version(2, Column = "LastModification", AccessType = typeof(PascalCaseMUnderScore))]
public Guid ID
{
   get { return m_ID; }
   set { m_ID = value; }
}

public int LastModification
{
   get { return m_LastModification; }
}


When I try to load a list I get the following exception:

Code:
"NHibernate.ADOException: Could not cast the value in field LastModi2_0_ of type Byte[] to the Type Int32Type..."


I already tried different data types such as byte[] or Int32 for the LastModification property. Does anybody have a working example of how to use NHibernate.Mapping.Attributes with a timestamp column?

Thanks, Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 10:24 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
So I'm getting a little bit closer to the solution. First, I found out that timestamp columns don't have anything to do with server time or so but merely are a sequential number that gets increased. That in itself is no problem as it still let's me do what I want, namely finding all the records that changed since the last request.

So I was able to map a timestamp column to a byte[] field using the standard <property> mapping. However, I'm still stuck with figuring out the proper construct to use a <version> or <timestamp> tag.

Any help appreciated :-)

Thanks, Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 10:55 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
I have never used the mapping attributes, but shouldnt the version attribute be on the LastModification property?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 11, 2006 2:25 pm 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
The timestamp type in sql server is in no way related to timestamp or version in NHibernate. The datatype can't be used by the clr

http://msdn2.microsoft.com/en-us/library/ms131092.aspx

When using the timestamp of sql server I map it as BinaryBlob.

<property access="field" name="m_timestamp" column="SearchItemTimestamp" type="BinaryBlob" insert="false" update="false"/>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.