Search code examples
c#nhibernatehqlnhibernate-4

How can I select a boolean literal in HQL?


I can select int and string literals in HQL like so:

select 'a string' as StringLiteral, 1 as IntLiteral from Eg.MyClass

but I haven't found a way to select a boolean literal. I've tried select true ..., and select new bool true ... but those cause HQL syntax exceptions.

Is there a way to select a boolean literal in HQL?

I have found a workaround (select case when (1=1) then true...), but that seems inefficient...


Solution

  • There are actually no real booleans in SQL (as in Select 1=1), except of in conditions. HQL turns "true" and "false" into 0 and 1 I think (something you can configure somewhere), but I guess it is still an integer.

    Simplest things you can most probably do is convert the integer to a boolean in memory after the query.