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.  [ 2 posts ] 
Author Message
 Post subject: DB Date is null throwing a SqlDateTime overflow exception!
PostPosted: Fri Apr 13, 2007 5:01 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Hi,

When I try to read some rows from my database (SQL Server) .. and some rows contain null date field, I get the following error:

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

I understand the date being to null is not between the specified dates, but what can I do to avoid this?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 14, 2007 1:59 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
If you are using .NET 2.0 you can use the DateTime? (Nullable DateTime) type in your entities.
What I do is have a Specification that I initialize my entity values with
Code:
           public class DateTimeSpecification
    {
        public static DateTime UNSPECIFIED_MIN = new DateTime(1800,1,1).Date;
        public static DateTime UNSPECIFIED_MAX = new DateTime(2999,12,31).Date;
    }


Since DateTime is a valueobject (struct) those are the only options I have come up with when dealing with the disparity between SQL DateTime limits and .NET.

Hope this helps
MIKE

_________________
If this helped...please remember to rate it!


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