在hibernate3下写hql语句,一定不要采用字符串拼接的方式,因为这样出来的结果往往是错误的和不可预料的,需要用?的方式来写.
比如find("from Article as t where t.keywork like '%中国%'");这样查询是得不到结果的,因为打出来的sql语句里,"中国"变成了"????",最好写成:
[code]
find("from Article as t where t.keywork like ?","%中国%");
[/code]
这样结果就正确了.
比如find("from Article as t where t.keywork like '%中国%'");这样查询是得不到结果的,因为打出来的sql语句里,"中国"变成了"????",最好写成:
[code]
find("from Article as t where t.keywork like ?","%中国%");
[/code]
这样结果就正确了.