NHibernate with string primary key and relationships
Posted
by
John_
on Stack Overflow
See other posts from Stack Overflow
or by John_
Published on 2009-01-04T22:41:26Z
Indexed on
2011/01/05
16:54 UTC
Read the original article
Hit count: 160
I've have just been stumped with this problem for an hour and I annoyingly found the problem eventually.
THE CIRCUMSTANCES
I have a table which users a string as a primary key, this table has various many to one and many to many relationships all off this primary key.
When searching for multiple items from the table all relationships were brought back. However whenever I tried to get the object by the primary key (string) it was not bringing back any relationships, they were always set to 0.
THE PARTIAL SOLUTION
So I looked into my logs to see what the SQL was doing and that was returning the correct results. So I tried various things in all sorts of random ways and eventually worked out it was. The case of the string being passed into the get method was not EXACTLY the same case as it was in the database, so when it tried to match up the relationship items with the main entity it was finding nothing (Or at least NHIbernate wasn't because as I stated above the SQL was actually returning the correct results)
THE REAL SOLUTION
Has anyone else come across this? If so how do you tell NHibernate to ignore case when matching SQL results to the entity? It is silly because it worked perfectly well before now all of a sudden it has started to pay attention to the case of the string.
© Stack Overflow or respective owner