Monday, July 07, 2008

NHibernate Entities Not Loading ID Values When Read From The DB

Problem: Your entities aren't loading up their ID properties when you do a find/read/whatever.  Other values for the entities load fine, but not the IDs.

Answer: Check the casing of your properties in your business objects and your mapping files.

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"


<id column="groupid" name="GroupID" >

  <generator class ="identity" />


Note the disconnect between the "default-access" attrib of the mapping element and the naming convention in id element's "name" attrib.  Ooops.  Either change the default-access or the casing of the name attrib:

<id column="groupid" name="GroupId" >

  <generator class ="identity" />


More on naming strategies in the NHib dox.

1 comment:

Brett Veenstra said...

You might find this helpful:

Subscribe (RSS)

The Leadership Journey