ObjectNotFoundException

Joseph LeBlanc's Avatar

Joseph LeBlanc

12 Apr, 2010 04:15 PM via web

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).

  1. Support Staff 2 Posted by James Gregory on 16 May, 2010 05:41 PM

    James Gregory's Avatar

    There's a NotFound.Ignore property on References, which you should be able to use.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    Insert the next number in this sequence: 10, 11, 12, 13, 14, ??