NHibernate FK is CHAR (6) and various queries fail because the PK child table is CHAR (6)
I have a legacy Oracle database that has multiple 1: n lookup tables that are based on CHAR (6) primary keys in child tables. Unfortunately, I'm not the only one who has problems with how NHibernate deals with char fields (especially primary keys). Cm:
- http://forum.hibernate.org/viewtopic.php?t=984281
- http://forum.hibernate.org/viewtopic.php?t=975743
- http://forum.hibernate.org/viewtopic.php?p=2382974
- http://www.hibernate.org/388.html
- ... and much more....
I'm going to implement a custom type to deal with the problems, but wanted to check if there is a better way as it still seems like there is some confusion about how to treat char fields as keys in the session. Get () ... and session.Load () ... (and therefore, since these tables are central to our application, I want to make sure it doesn't need to be redone). I'm sure I'm not the only one who ran into this, and I would greatly appreciate any guidance from more experienced NHibernate users.
To make things more interesting, using NHibernate with Oracle does throw in some curves that I didn't expect.
source to share
Looks like update 2.0.1. GA solved most of the problems (if they weren't a problem for me to misconfigure). Lazy load load fine on foreign keys even if they are char (6) but length less than 6. session.Get and session.Load work fine if you include trailing spaces.
I can still implement UserType to get rid of trailing spaces for display.
source to share