-->
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.  [ 1 post ] 
Author Message
 Post subject: Enforce use of Nullable Types for all mapped NULL columns
PostPosted: Tue Jul 29, 2008 5:32 am 
Newbie

Joined: Tue Jul 29, 2008 5:11 am
Posts: 5
I am using NH 1.2.1 with VB.NET 2.0.

I ran into a problem that took me some time to understand. I had a column in the database with a nullable int. It was mapped like this:

Code:
<property name="ColumnName" />


The object loaded fine but an UPDATE was issued even though I had not changed anything. Running some logging i finally realized that I had not declared my property as nullable. It was declared like this (only showing private variable):

Code:
Private _ColumnName As Integer


When I changed it to this the UPDATE did not occur:

Code:
Private _ColumnName As Integer?


What was happening was that the database value was NULL but since the property was not declared as a Nullable type it was set to default value of zero. Then when NH checked for changes it got (0 != NULL) and tried to UPDATE.

Now this is all fine but it is an easy mistake to make and I think it is very dangerous to generate an UPDATE that you may not be aware of.

Because of this I want to enforce the use of Nullable types in the project so if a programmer tries to map a nullable column in the database to a non-nullable valuetype property an exception occures when NH tries to create the object instead of NH silently setting the property to default value and then generating an UPDATE.

Is there anyway to enforce this mapping rule?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.