---
title: "不要在HQL语句中拼字符串!"
author: "DavyLee"
date: "2007-09-25T16:40:15Z"
tags: []
slug: "hql"
draft: false
lastmod: "2007-09-25T16:40:15Z"
id: 126956
url: "https://davylee.iteye.com/blog/126956"
---

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

```

find("from Article as t where t.keywork like ?","%中国%");

```

这样结果就正确了.