簡體   English   中英

Nhibernate 2:CreateQuery不支持中文字符

[英]Nhibernate 2: CreateQuery not supporting chinese character

以下是我的代碼:

String hsql = "from Customer c where c.name='測試' ";
IQuery query = _session.CreateQuery(hsql);
query.List();

在執行時,沒有引發異常,但是沒有查詢結果返回(它們應該根據條件c.name='測試'

這是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='????')

hsql中的中文字符“測試”變為“ ????” 在SQL中。

通過Nhibernate添加客戶時,漢字保存成功。 這里的問題僅在我使用CreateQuery搜索文本時出現。 任何幫助將不勝感激。

您可以使用參數嘗試嗎?

String hsql = "from Customer c where c.name=:name";
IQuery query = _session.CreateQuery(hsql).SetString("name", "測試");
query.List();

Hibernate查詢中的相關Unicode字符串

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM