R – NHibernate FK is a CHAR(6), and various queries fail due to the child table PK being CHAR(6)


I have a legacy Oracle database that has multiple 1:n lookup tables that are based on CHAR(6) primary keys in the child tables. Unfortunately, I'm not the only one who has problems with how NHibernate deals with char fields (especially with those as primary keys). See:

I'm about to implement a custom usertype to deal with the issues, but wanted to check to see if there's a better way as there still seems to be some confusion over how to deal char fields as keys in session.Get()… and session.Load()… (and therefore, as these tables are central to our application, I want to make sure it doesn't have to be redone). I am sure I am not the only one to have run into this, and I'd greatly appreciate any recommendations from more experienced NHibernate users out there.

To make things more interesting, using NHibernate with Oracle does throw some curveballs that I wasn't expecting.

Best Solution

Looks like an update to 2.0.1 GA solved most of the issues (if they were not issues to me misconfiguring something). Lazy loads load fine on foreign keys even if they are char(6), but length is less than 6. session.Get and session.Load work fine natively as well if you include the trailing spaces.

I might still implement a UserType to get rid of trailing spaces for display.

Related Question