Thursday, September 3, 2009

NHibernate - Embedded Resource

Although I'm using NHibernate for years, I keep making the same mistake. If you're using the default XML mapping to map your domain model to your database, you'll end up with a lot of .hbm.xml files.

So you start up your application, initialize the SessionFactory, and start your first HQL query and then oops...

NHibernate.QueryException: in expected: (possibly an invalid or unmapped class name was used in the query)

What happened? I forgot to change the Build Action of the .hbm.xml files to "Embedded Resource". This error could be very annoying if you start looking in the wrong places. So always start with checking your build actions if you get an error after adding some new mapping files. It could save you a lot of time.

Of course nowadays you no longer need to be confronted with this type of error because you have 2 alternatives available: Attribute based mapping and Fluent NHibernate.

No comments: