我有一个这样的 Hibernate SQL 查询:
public void funcA(String str) {
StringBuilder sql = new StringBuilder();
sql.append("select fieldA from tableA where fieldB like '%:searchKey%'");
...
session.createSQLQuery(sql.toString())
.addScalar("fieldA", StandardBasicTypes.STRING)
.setParameter("searchKey", str);
...
}
当我进行这样的查询时query.list()
,出现以下错误:
[WARNING ] SQL Error: -7, SQLState: 42601[ERROR ] The character "%" following "fieldB like" is not valid.
[ERROR ] An error occurred during implicit system action type "2". Information returned for the error includes SQLCODE "-7", SQLSTATE "42601" and message tokens "%|fieldB like".
我可以知道我该如何解决这个问题吗?