我在我的项目中使用Nhibernate 2.1.0。
我有一个Item类,其属性为Path,以及以下命名查询:
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
<sql-query name='updateUNC'>
<query-param name='oldUNC' type='String'/>
<query-param name='newUNC' type='String'/>
<![CDATA[
update Item s set
s.Path= replace(s.Path,:oldUNC, :newUNC),
]]>
</sql-query>
</hibernate-mapping>
我使用以下代码执行命名查询:
session.GetNamedQuery("updateUNC")
.SetString("oldUNC", "old")
.SetString("newUNC", "new")
.ExecuteUpdate();
但我得到以下例外:
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException was unhandled
Message="Can't determine SqlType of parameter name=oldUNC, expectedType=Unknow\n Possible cause: wrong case-sensitive property-name."
Source="NHibernate"
StackTrace:
at NHibernate.Hql.Ast.ANTLR.Exec.BasicExecutor.Execute(QueryParameters parameters, ISessionImplementor session) in C:\Projects\Nhibernate\nhibernate2.1.0\src\NHibernate\Hql\Ast\ANTLR\Exec\BasicExecutor.cs:line 66
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.ExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session) in C:\Projects\Nhibernate\nhibernate2.1.0\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs:line 149
at NHibernate.Engine.Query.HQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session) in C:\Projects\Nhibernate\nhibernate2.1.0\src\NHibernate\Engine\Query\HQLQueryPlan.cs:line 328
at NHibernate.Impl.StatelessSessionImpl.ExecuteUpdate(String query, QueryParameters queryParameters) in C:\Projects\Nhibernate\nhibernate2.1.0\src\NHibernate\Impl\StatelessSessionImpl.cs:line 962
at NHibernate.Impl.QueryImpl.ExecuteUpdate() in C:\Projects\Nhibernate\nhibernate2.1.0\src\NHibernate\Impl\QueryImpl.cs:line 120
at Catalog.Repository.ItemsRepository.ChangeUNC(String oldUNC, String newUNC) in C:\Projects\Catalog\Catalog\Repository\ItemsRepository.cs:line 148
我还尝试使用SetParameter&lt; string&gt;设置参数值。和SetParameter(“:oldUNC”,“old”NHibernateUtil.String)但它也失败了同样的错误。这就像NHibernate只是忽略我说tet参数值是字符串:(。
答案 0 :(得分:0)
只是猜测:您是否尝试在映射文件中使用小写字母编写字符串?
<query-param name='oldUNC' type='string'/>