I noticed something interesting when profiling one of our web apps. Many of the pages in this app are read only, but on some pages I noticed that NH was running updates on one of my collections. Worse yet, it was setting values that should be null to 0, which caused big problems. This app uses the usual session per request pattern, with a unit of work wrapped around each request. Session.Flush is never called, it's always flushed via transaction.commit.
After some checking, I realized my class and table had some mismatches. The table had nullable columns, but the class had the properties as regular decimals - not nullable decimals. What I guess is happening is that when the collection gets loaded, the properties get hydrated with 0s instead of nulls (duh). NH thinks that the object was changed (or doesn't match the original values from the db), and when commit() is called those changes are flushed. I realize that is expected behavior, but short of making sure I use nullables in my classes when the underlying db type is nullable (which I have to do anyway, my bad), is there anything else I can do to prevent this without drastically altering how I manage the session? -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
