-->
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: null DateTime - "SqlDateTime overflow. Must be between.
PostPosted: Tue Jan 27, 2009 2:29 am 
Beginner
Beginner

Joined: Mon Jan 05, 2009 7:08 am
Posts: 24
hello

I ran into a problem with NHibernate - "LastUpdate" field of my class defaults to null (NULL is declared in database table schema as well) but when inserted into NHibernate I got error:
Code:
+      [System.Data.SqlTypes.SqlTypeException]   {"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."}   System.Data.SqlTypes.SqlTypeException



I want to avoid hardcoding "NULL" to 1JAN1753 - any alternatives? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 2:48 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Do you use DateTime or DateTime? ? If you want to use NULL values you have to use DateTime? !

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: yes I'm using DateTime (both sql table schema AND C# class)
PostPosted: Tue Jan 27, 2009 3:02 am 
Beginner
Beginner

Joined: Mon Jan 05, 2009 7:08 am
Posts: 24
Yes I'm using DateTime in both my SQL table schema AND C# class definition (and mapping file NHibernate type)

[CreateDate] [datetime] NULL DEFAULT (GETDATE()),
[CreatedBy] [bigint] NULL DEFAULT (-1), /* TODO: Add constraint this will not be Constant.INVALID */
[LastUpdate] [datetime] NULL, << I can't insert NULL because of problem I mentioned
[LastUpdateBy] [bigint] NULL,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 3:18 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
No, the problem ist that the allowed data range in .Net and in SQL Server differs. DateTime is a struct and therefore a value type. Meaning it can't be NULL. An uninitalized DateTime is something about "12:00:00 midnight, January 1, 0001 ". SQL Server has a minimum of "1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM". If you really want NULL values you have to use the nullable version DateTime? in your class. Mapping with hibernate and schema definition in SQL Server stays the same.

http://msdn.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: yes NULL prefered over 1/1/1753
PostPosted: Tue Jan 27, 2009 3:44 am 
Beginner
Beginner

Joined: Mon Jan 05, 2009 7:08 am
Posts: 24
yes really want NULL in LastUpdate field in database - because support guys can use this syntax to find Person's who hasn't been updated.

SELECT * FROM Person WHERE LastUpdate is NULL

... instead of

SELECT * FROM Person WHERE LastUpdate>'1/1/1753'

Thanks


Top
 Profile  
 
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.