-->
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: Nullable and non-nullable columns
PostPosted: Thu Feb 22, 2007 1:29 pm 
Newbie

Joined: Thu May 04, 2006 2:42 pm
Posts: 10
Location: Columbus, OH
I ran into an interesting problem today.

I have a column in my database that is a boolean column that allows nulls. This column was mapped to a property of type "bool" (non-nullable).

So here's the basic flow of things:

1) You load up an object that has one of these properties
2) You then execute some other query that involves the table that you did the first select from
3) NHibernate tries to persist any objects that are dirty before it does the query
4) When it loaded up our boolean property and the value in the database was NULL, it couldn't put NULL into the property, so it puts in "false" instead. So when it checks to see if the object is dirty, NULL != false, so it tries to save this object.

I would rather have it throw an exception than interpret a NULL as false, because NULL != false. Now granted, this problem is partially caused by my own ignorance when I did the mapping, but I would rather have it tell me that something is wrong rather than doing all of these unnecessary saves. This is especially bad in my application because sometimes a user doesn't have permission to save a certain object and it causes the app to blow up.

So...... is there a way to tell nHibernate to throw an exception instead of converting NULL to false?

Thanks everyone,
Jon

_________________
Jon Kruger
http://jonkruger.com/blog


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 2:23 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Write an implementation of IUserType, do whatever you want there.


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.