Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate找不到命名参数异常_Hibernate_Spring Mvc - Fatal编程技术网

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;
    }