-->
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: SQL Server Date Time breaks
PostPosted: Wed Jun 15, 2005 6:01 am 
Hi all

Newbie here, but after two days of exceptions finally tracked down my own problem and thought I'd try and save anyone else from same.

Under some (and I haven't isolated them) conditions, there is a clash between System.Data.SqlTypes.SqlDateTime and System.DateTime, which appear to be (logically) the default mapping for this type.

SqlDateTime supports null, but DateTime does not. Going the other way, the default min value (zero, if you like) for DateTime isn't zero - it's midnight, 01 Jan 0001.

When you try to write this value to the SqlDateTime and into the database, somewhere, an overflow exception is thrown - the lowest value supported by SqlDateTime is midnight, 1st Jan 1753.

My fix, hopefully a correct one, is to throb a chunk of code from Type\TimeType.cs into Type\DateTimeType.cs as follows:
Line 66 of Type\DateTimeType.cs (in the public override void Set function) changes from
Code:
parm.Value = new DateTime( dateValue.Year, dateValue.Month, dateValue.Day, dateValue.Hour, dateValue.Minute, dateValue.Second );

to
Code:
         if (dateValue == DateTime.MinValue)
            parm.Value = DBNull.Value;
         else
            parm.Value = new DateTime( dateValue.Year, dateValue.Month, dateValue.Day, dateValue.Hour, dateValue.Minute, dateValue.Second );


Hopefully this is of some use, maybe even an active contributor could slide it in on the next release?

Cheers

simon.lockwood@systemic.com.au


Top
  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 4:07 pm 
Beginner
Beginner

Joined: Sat Apr 17, 2004 1:11 am
Posts: 36
I'm running into this now as well - any word from someone regarding this at all?

I'm loading a list of all objects of a certain type and then later on committing the transaction. The session sees an object with a date of 1/1/0001 as dirty and attempts to flush and update and I get an exception that's listed below.

This is bad...

Code:
2005-11-10 14:59:00,523 [4092] NHibernate.Util.ADOExceptionReporter.LogExceptions(:0) - could not update: [BOM.Asset#2]
System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
   at System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan value)
   at System.Data.SqlTypes.SqlDateTime.FromDateTime(DateTime value)
   at System.Data.SqlTypes.SqlDateTime..ctor(DateTime value)
   at System.Data.SqlClient.MetaType.FromDateTime(DateTime dateTime, Byte cb)
   at System.Data.SqlClient.TdsParser.WriteValue(Object value, MetaType type, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
   at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor se
ssion)
2005-11-10 14:59:00,585 [4092] NHibernate.Util.ADOExceptionReporter.LogExceptions(:0) - System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:5
9:59 PM.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 10:58 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 6:21 pm
Posts: 24
Location: Antwerp, Belgium
This is biting me too and I'm using NH 1.0.2.

Is there a reason not to add the change suggested by the OP ?
Is there a better way to avoid this problem ?
If anyone can shed some light, I'd be very grateful.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 11:43 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:09 pm
Posts: 23
Um, have a look at Nullables:
http://nhibernate.sourceforge.net/nh-docs/html/Nullables.html


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.