I'm trying to to do a discriminator based subclass mapping with NHibernate 2.0.1 and PostgreSQL. My discriminator is a formula looking for a specific value in a column to identify a special subclass. I ran into a couple issues.
First off, the documentation fails to mention that, in most cases, you need to surround your formula with parentheses. My first attempt had the discriminator formula as "column = 'magic value'", which hibernate then translated in the query as "... where column = 'magic value' = 1 ..." which of course is invalid.
The second problem, after fixing the parentheses issue, is that boolean values are not handled entirely correctly in postgresql. The postgresql dialects inherit the default implementation of Dialect.ToBooleanValueString, which returns "1" or "0". When working with a boolean formula discriminator, this results in "... where (column = 'magic value') = 1 ...", and postgresql complains: "ERROR 42883: operator does not exist: boolean = integer."
I was able to fix this by creating a custom dialect that overrides ToBooleanValueString and returns the postgresql "TRUE" and "FALSE" constants. Is this a proper fix for this issue? Should I submit a patch to Jira? Do other databases need a similar fix for not having an implicit conversion from integer to boolean?
|