-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: version related problem using timestamp ===> Urgent
PostPosted: Tue Jul 18, 2006 9:45 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
i have version proeprty defined in my mapping

<version name="Version" column="TimeStamp" type="Timestamp" unsaved-value="null" />

(my database table contains column "TimeStamp" which is of type DateTime, i have initialized all my rows in database table to current date
i.e. 1900-01-01 00:00:07.220)

(i have tried keeping datatype in table as TimeStamp but it gives mapping error)

corresponding to this i have proeprty defined in my class

public virtual DateTime Version
{
get { return _version; }
set { _version =value; }
}

I m getting error

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Can anybody help ???????


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 12:28 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
version is usually used with ints (or longs). i find <timestamp> more clear when using dates:

Code:
<timestamp name="LastUpdate" column="TimeStamp" />


in both cases, whether using <version> or <timestamp> the declarations need to be directly under the <id> declaration. also, versioning using timestamp is _slightly_ more unsafe than using a numeric <version> strategy. and finally, the error you are getting is usually tied to a NULL date value so for some reason, although your dates are set in the DB, .NET is getting NULL. what do you see in the debugger?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 2:06 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
While reading from the database , it is getting the correct value as u said it is not taking null.
people may say its unsafe to use timestamp, but i want to use timestamp and i want solution for that.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 9:54 am 
Newbie

Joined: Sun May 28, 2006 7:42 pm
Posts: 19
Location: Italy
What about sql server exp 2005 that store timestamp value as byte[]. How to map it?. Property in Business Object must be a byte[] or a Timestamp type?. If must be a byte[], how to check versioning?.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 4:48 pm 
Newbie

Joined: Sun May 28, 2006 7:42 pm
Posts: 19
Location: Italy
ovidius wrote:
What about sql server exp 2005 that store timestamp value as byte[]. How to map it?. Property in Business Object must be a byte[] or a Timestamp type?. If must be a byte[], how to check versioning?.

Thanks


I can't find solution for this )-:

Someone can help me?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 26, 2006 11:43 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
Quote:
people may say its unsafe to use timestamp, but i want to use timestamp and i want solution for that.


apologies if i appeared to offend u. i hear you. i just had a thought regarding your problem, though...

you have your version declared as such:

Code:
<version name="Version" column="TimeStamp" type="Timestamp" unsaved-value="null" />


but in your class you have :

Code:
private DateTime _version;
public virtual DateTime Version
{
   get { return _version; }
   set { _version =value; }
}


that won't work because you've got the unsaved-value set as NULLable which means you have to set the member variable/Property as NHibernate.NullableDateTime:

Code:
private NHibernate.NullableDateTime _version;
public virtual NHibernate.NullableDateTime Version
{
   get { return _version; }
   set { _version =value; }
}


personally, I think you should change the unsaved-value to something other than NULL. I haven't tried it but what about DateTime.Min or something?

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 30, 2006 10:35 am 
Newbie

Joined: Sun May 28, 2006 7:42 pm
Posts: 19
Location: Italy
ovidius wrote:
What about sql server exp 2005 that store timestamp value as byte[]. How to map it?. Property in Business Object must be a byte[] or a Timestamp type?. If must be a byte[], how to check versioning?.

Thanks


UP

No one know more about this problem ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 30, 2006 11:21 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate doesn't support database timestamps directly. You can probably map a timestamp as a byte array with insert="false", update="false" and use Refresh to force NHibernate to re-read its value from the database when required.


Top
 Profile  
 
 Post subject: Mapping a SQL Server 2005 Timestamp
PostPosted: Wed Apr 25, 2007 5:45 pm 
Beginner
Beginner

Joined: Tue Sep 14, 2004 1:03 pm
Posts: 33
Location: Calgary, Alberta Canada
It is unfortunate the NHibernate timestamp or version does not support the SQL Server 2005 Byte[] used for the database timestamp type. NHibernate for .net which is m$ and so is SQL Server 2005.

Anyway, this is a late response and I digress

I map the timestamp like so:
<property name="TimeStamp"
column="VERSION"
type="System.Byte[]"
not-null="true"
insert="false"
update="false"
unique="true"/>

In my buisness class, I usually have a field called version of type Int64 and create a property as follows (that takes the Byte[])

protected virtual Byte[] TimeStamp {
get { return BitConverter.GetBytes(version); }
set { version = BitConverter.ToInt64(value, 0); }
}

but of course you could use the BitConverter to make it a datetime if you want as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 9:21 am 
Newbie

Joined: Tue Mar 06, 2007 5:28 pm
Posts: 6
Do you then do a manual (programmatic) concurrency check with that property?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 1:56 pm 
Beginner
Beginner

Joined: Tue Sep 14, 2004 1:03 pm
Posts: 33
Location: Calgary, Alberta Canada
Yes, you would have to. SQL Server 2005 does not allow to update a Timestamp field as this is completely managed by the server. So, you have to manage versioning yourself.

This can be done through a delegate on the business class the would notify that the class has been altered. It can be done by createing an IPersisteble interface for all your persisteble buisness objects.
The interface could have a property called IsAltered or something and maybe have some methods to be used for conflict resolution.
Your buisness layer would then check for the is altered (if it hasn't been altered no point in updating anything) and do whatever is required.

Prior to persisting changes the DAO would check the version currently stored for the object in the database, if it does not match the transient object, then it has been altered since we originally pulled it from the database and would have to deal with conflict resolution.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 2:12 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The latest NHibernate version (1.2.0.CR2) supports generated properties. You can map a property as generated="insert" or generated="always" and NHibernate will read back its value after an insert or insert/update.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 2:21 pm 
Newbie

Joined: Tue Mar 06, 2007 5:28 pm
Posts: 6
Just downloaded but haven't tested yet but eagerly await it. That makes it easier but I don't believe it'll allow me to use a SQL Server "Timestamp" datatype (byte[]) for the <version> - I'll still have to manually compare?


Top
 Profile  
 
 Post subject: Re: version related problem using timestamp ===> Urgent
PostPosted: Wed May 09, 2007 8:25 am 
Newbie

Joined: Thu Apr 12, 2007 7:46 am
Posts: 3
Location: Switzerland
pcmedsinge wrote:
public virtual DateTime Version
{
get { return _version; }
set { _version =value; }
}

I m getting error

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.


The problem is that can SqlDateTime be Null but DateTime not. And it will set DateTime.MinValue (01-01-0001) to your field when a Null comes from the db
use Nullable<DateTime> in .Net 2.0 or NHibernate.NullableDateTime in 1.0 instead of DateTime and you will be fine


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 2:55 am 
Newbie

Joined: Mon May 21, 2007 2:38 am
Posts: 2
Location: Denmark
dsbdev wrote:
Just downloaded but haven't tested yet but eagerly await it. That makes it easier but I don't believe it'll allow me to use a SQL Server "Timestamp" datatype (byte[]) for the <version> - I'll still have to manually compare?


Any success?
I started with NHibernate only last week, and face the exact same problem.
It seems that insert="false" may not be used with <version> tag, so even if generated="always" NH tries to insert/update the mssql timestamp column.
I guess one have to implement IUserVersionType and IUserType, but I have no idea how to go about that - HELP anyone!?

My app have to work against a legacy database, and live with existing MS Acces frontend clients, so optimistic concurrency is a must, and this issue is, sadly, presently a showstopper. I'm sure however, that a solution exist...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.