Not completely sure about this just yet, but when we save an entity over NHibernate that includes a field value of NULL fo开发者_StackOverflowr a column that is NOT NULL (but has a DEFAULT value), the operation fails.
We tried out the same schema by throwing an INSERT statement on it, completely leaving out the NOT NULL field (as opposed to explicitly declaring it as NULL), and that worked.
Which makes us believe that NHibernate is setting up the SQL statement in such a way that the NOT NULL field is explicitly declared to be NULL, which causes the INSERT error.
Is there a way to make NHibernate leave out this field from the SQL statement if it is NULL? For what it's worth, it's a string field for a NOT NULL column with a DEFAULT ('').
You can use the dynamic-insert attribute on your class element (see 5.1.3. Class). Or, if you are using FluentNHibernate there is a method named DynamicInsert (iirc) that you can call when setting up the mapping.
FYI, There is a corresponding attribute and Fluent function for Dynamic Update, too.
精彩评论