-->
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.  [ 5 posts ] 
Author Message
 Post subject: Could not cast the value in field ... to the Type Timestamp
PostPosted: Mon May 30, 2005 11:25 pm 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
How do you map TimeStamp (SQL Server) to DateTime (.NET) datatype? I ran into the following error:

"Could not cast the value in field ts_times4_ to the Type TimestampType. Please check to make sure that the mapping is correct and that your DataProvider supports this Data Type."

My table:
CREATE TABLE [some_table] (
[field1] [int] NOT NULL ,
... other fields ...
[ts_timestamp] [timestamp] NULL ,
.... other fields ...
) ON [PRIMARY]

My class:

Namespace ....

Public Class AtDivision
... other properties ...
Protected _timestamp As DateTime

' How do I map to data type 'Timestamp'?
Public Property Timestamp() As DateTime
....
End Property

End Class

I tried this in my mapping file, but, ran into the error I mentioned...
property name="Timestamp" column= "ts_timestamp" type="Timestamp"


Top
 Profile  
 
 Post subject: Anyone...?
PostPosted: Wed Jun 01, 2005 3:04 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Guys... Anyone? Show me the light :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 6:12 pm 
Regular
Regular

Joined: Mon May 16, 2005 2:15 pm
Posts: 59
I'm not 100 percent sure. But, I can tell you that a 'timestamp' data type in SQL Server 2000 is NOT the same as DateTime. I think it would be equivelent to a binary(16).


Top
 Profile  
 
 Post subject: Byte[]
PostPosted: Thu Jun 02, 2005 9:50 am 
An SQL Server timestamp maps to a .NET System.Byte[]; it should be handled as an NH BinaryType. However, timestamp isn't listed as a type in the SQL 2k dialect - possibly because it's not updateable? I'm not sure whether the dialect is just used to reflect types from the database.

A timestamp column is not particularly useful to you if you can't use it for optimistic concurrency checking though - I haven't yet worked out how to do this (see my database row versioning topic).


Top
  
 
 Post subject: clarification
PostPosted: Thu Jun 02, 2005 9:48 pm 
Sorry - re-reading the original post, I wasn't very clear.

An SQL Server timestamp is IMO very confusingly named as it does not contain any date or time data. Microsoft now prefer that you use the 'rowversion' synonym instead of 'timestamp'. Think of it as a read-only GUID (binary(8)) that the database changes each time there's a row update.

If you want to store date & time data, use a datetime column instead of timestamp.

Cheers,
Sam.


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