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
|