ObjectNotFoundException
The project I'm working on has a legacy database with lots of information in it that's used to alter application behavior. Basically I'm stuck with something that I have to be super careful about changing.
Onto my problem. In this database is a table and in this table is a column. This column contains integers and most of the pre-existing data have a value of zero for this column. The problem is that this column is in fact a foreign key reference to another entity, it was just never defined as such in the database schema.
Now in my new code I defined my Fluent-NHibernate mapping to treat this column as a Reference so that I don't have to deal with entity id's directly in my code. This works fine until I come across an entity that has a value of 0 in this column.
NHibernate thinks that a value of 0 is a valid reference. When my code tries to use that referenced object I get an ObjectNotFoundException as obviously there is no object in my database with an id of 0.
How can I, either through mapping or some kind of convention, get NHibernate to treat id's that are 0 the same as if it was NULL?
The only answer I've been able to find so far is to use the SetAttribute( "not-found", "ignore" ); API but that method doesn't seem to exist in the version I'm using (1.0).
Support Staff 2 Posted by James Gregory on 16 May, 2010 05:41 PM
There's a
NotFound.Ignore
property onReferences
, which you should be able to use.