-1
我的異常消息是: Hibernate無法找到名爲的參數異常
org.hibernate.QueryParameterException: could not locate named parameter [searchKey] at
org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:148) at
org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:165) at
org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:523) at
org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:493) at
com.si.bse.dao.impl.SearchDaoImpl.getClientList(SearchDaoImpl.java:99) at
com.si.bse.services.impl.SearchServicesImpl.getClientList(SearchServicesImpl.java:32)
和被扔是代碼:
@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;
}
爲什麼Hibernate將找不到我命名的參數?
嘗試使用'select * from客戶端c加入clientcategory cc on c.id = cc.client_id where match(cc.clientkeyword)against(:searchKey in boolean mode)' – Amogh
您可以在'setParameter'中指定參數類型。看看https://docs.jboss.org/hibernate/core/3.2/api/org/hibernate/Query.html#setParameter%28java.lang.String,%20java.lang.Object,%20org.hibernate.type .Type%29 – Amogh
我已經整理好你的代碼和異常塊。確保你已經徹底研究過這個例外。這應該是一個相當簡單的修復。 – JamesENL