-->
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.  [ 3 posts ] 
Author Message
 Post subject: Null value substitution
PostPosted: Mon Feb 04, 2008 7:46 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
Hibernate version:
1.2.1.4000

Name and version of the database you are using:
Microsoft SQL Server 9.00.1406.00

I have two classes:

Code:
ClassA
{
    Date1{get;set;}
}

ClassB:ClassA
{
    Date2{get;set;}
}


In my DDL the column for Date2 must be nullable, however in my class it's not a nullable type. Is there a way to do null value substitution for this?

Also, is there way to substitue null for any date less than sql servers min date of 1/1/1753?

Basically, we dont allow nulls in our objects and that seems to be causing some problems here. We use DateTime.MinValue or DateTime.MaxValue as the default value for date fields.


Top
 Profile  
 
 Post subject: Null value substitution
PostPosted: Tue Feb 05, 2008 5:49 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi Mike,

I suspect that you really want your database to reflect the business logic (if the business doesn't allow nulls, the database shouldn't).

However, you could have a completely protected (nullable) field for the mapping, then a public accessor for your business use:

Code:
...
// mapped to the database field using NHibernate
protected virtual DateTime? PersistedDate2
{
    get { return _date2; }
    set { _date2 = value; }
}

public virtual DateTime Date2
{
    get { return PersistedDate2.GetValueOrDefault(); }
    set
    {
        // whatever 'set' logic you want ...
    }
}
...


Regards,
Richard


Top
 Profile  
 
 Post subject: Re: Null value substitution
PostPosted: Tue Feb 05, 2008 10:52 am 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
FlukeFan wrote:
Hi Mike,
I suspect that you really want your database to reflect the business logic (if the business doesn't allow nulls, the database shouldn't).

However, you could have a completely protected (nullable) field for the mapping, then a public accessor for your business use:


Excellent idea, sometimes the simple solutions escape us. I was looking for something a little more complex. Thanks.


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