<class name="Foo">
<property name="Bar" column="`Bar?`" />
</class>
This convention is used by NHibernate to generate SQL with the column name wrapped appropriately (e.g. [] for SQL Server). This works as intended for ICriteria queries and for HQL queries returning tuples in the following form:
session.CreateQuery("select Bar from Foo").List();
For SQL Server this results in the following SQL:
select foo0_.[Bar?] as col_0_0_
from Foo foo0_
The problem occurs if you use the entity selection form of the HQL query in conjunction with the generic List
session.CreateQuery("select foo from Foo foo").List<Foo>();
In this scenario, when constructing the SQL statement NHibernate interprets the question mark as a position parameter placeholder and substitutes the question mark with the parameter, i.e. the query winds up containing this column
foo0_.[Bar@p0]
instead of
foo0_.[Bar?]
Unfortunately this is a fault in NHibernate 3.1:
http://stackoverflow.com/questions/5805617/escaping-a-question-mark-character-in-a-column-name-in-nhibernate
No comments:
Post a Comment