Hibernate找不到命名参数异常
我的例外信息是: 抛出它的代码是:Hibernate找不到命名参数异常,hibernate,spring-mvc,Hibernate,Spring Mvc,我的例外信息是: 抛出它的代码是: @SuppressWarnings("unchecked") @Transactional @Override public List<Client> getClientList(String searchWord) { String sql = "select * from client c join clientcategory cc on c.id=cc.client_id where match(cc.clientkeyword)
@SuppressWarnings("unchecked")
@Transactional
@Override
public List<Client> getClientList(String searchWord) {
String sql = "select * from client c join clientcategory cc on c.id=cc.client_id where match(cc.clientkeyword) against(':searchKey' in boolean mode)";
SQLQuery query = (SQLQuery) getCurrentSession().createSQLQuery(sql).addEntity(Client.class).setParameter("searchKey", searchWord);
List result = query.list();
return result;
}
@SuppressWarnings(“未选中”)
@交易的
@凌驾
公共列表getClientList(字符串搜索词){
String sql=“select*from client c join clientcategory cc on c.id=cc.client_id,其中匹配(cc.clientkeyword)对(“:searchKey”在布尔模式下)”;
SQLQuery query=(SQLQuery)getCurrentSession().createSQLQuery(sql).addEntity(Client.class).setParameter(“searchKey”,searchWord);
列表结果=query.List();
返回结果;
}
为什么Hibernate找不到我的命名参数?对于参数占位符
':searchKey'
,不需要使用单引号'
。删除该引号可能会解决您的问题
因此,查询将是:
select*from client c join clientcategory cc on c.id=cc.client\u id,其中匹配(cc.clientkeyword)与(:布尔模式下的searchKey)
您可以使用重载的setParameter()指定参数的数据类型,它接受3个参数
有关方法Plz的更多信息,请参阅。尝试使用
select*from client c join clientcategory cc on c.id=cc.client\u id进行查询,其中匹配(cc.clientkeyword)与(:searchKey in boolean mode)
您可以在setParameter
中指定参数类型。看一看,我已经整理了你的代码和异常块。确保您已彻底研究了此异常。这应该是一个相当简单的修复方法。非常感谢@amoh它的工作原理:)
@SuppressWarnings("unchecked")
@Transactional
@Override
public List<Client> getClientList(String searchWord) {
String sql = "select * from client c join clientcategory cc on c.id=cc.client_id where match(cc.clientkeyword) against(':searchKey' in boolean mode)";
SQLQuery query = (SQLQuery) getCurrentSession().createSQLQuery(sql).addEntity(Client.class).setParameter("searchKey", searchWord);
List result = query.list();
return result;
}