Friday, March 27, 2009
Google Voice
Wednesday, January 07, 2009
NHibernate.MappingException: Unknown entity class
I spent an hour finding and fixing a problem that should have been much faster last night. This post is to make sure I don't forget what I learned :-) I’m experimenting with NHibernate, and specifically the FluentNHibernate functionality. I was trying to get a test running, and I kept getting the error: “NHibernate.MappingException: Unknown entity class BLAH” (where BLAH was the persistable class I was building) during the mapping setup of the test.
I dug all over the place (assuming I had a typo in a namespace or some other stupid thing like that), and couldn’t find the problem until I ran Reflector on the assembly that held the mappings. Only then did I notice that the mapping class was grayed out (in other words, I’d failed to make the map public -- in fact when I created the class, I failed to set accessibility at all so it was set to the default accessibility of internal). Once I set access to the class to public, the test ran as expected, and I was able to finish setting things up.
public class BLAHMap : ClassMap<BLAH> {
public BLAH() {...}
}
I’m sure this is in the docs somewhere, but the bottom line is: don’t forget to make mapping classes public. The other takeaway from this is that it’s good to have multiple ways of looking at something – reflector showed the problem because it had a different way of displaying information that wasn’t visible just by looking at the editor.