[英]Nhibernate 2: CreateQuery not supporting chinese character
Following is my code: 以下是我的代码:
String hsql = "from Customer c where c.name='测试' ";
IQuery query = _session.CreateQuery(hsql);
query.List();
when executing, no exception thrown, but no query result return (they should return based the condition c.name='测试'
) 在执行时,没有引发异常,但是没有查询结果返回(它们应该根据条件
c.name='测试'
)
this is the sql NHibernate generate for the hsql: 这是NHibernate为hsql生成的sql:
select customer0_.CUSTOMER_NO as CUSTOMER1_, customer0_.CODE as CODE9_, customer0_.NAME as NAME9_, customer0_.STATUS as STATUS9_, customer0_.LAST_OPE RATOR_NO as LAST5_9_
from CUSTOMER customer0_ where (customer0_.NAME='????')
The chinese characters '测试' in hsql become '????' hsql中的中文字符“测试”变为“ ????” in sql.
在SQL中。
The chinese characters are saving successfully when I am adding a customer through Nhibernate. 通过Nhibernate添加客户时,汉字保存成功。 Here the issue is only when I am searching a text using CreateQuery.
这里的问题仅在我使用CreateQuery搜索文本时出现。 Any help will be appreciated.
任何帮助将不胜感激。
Can you try it using a parameter? 您可以使用参数尝试吗?
String hsql = "from Customer c where c.name=:name";
IQuery query = _session.CreateQuery(hsql).SetString("name", "测试");
query.List();
related Unicode String in Hibernate Queries Hibernate查询中的相关Unicode字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.