代码:
@Override
public void delete(int id) {
// TODO Auto-generated method stub
Session session = getSession();
String hql = "delete from Services where id = ?";
Query q = session.createQuery(hql);
q.setParameter("id", id);
q.executeUpdate();
}
错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [/PodCloud] threw exception [Request processing failed; nested exception is org.hibernate.QueryParameterException: could not locate named parameter [id]] with root cause
org.hibernate.QueryParameterException: could not locate named parameter [id]
at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:100)
at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:106)
at org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:466)
at org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:436)
at com.founder.mrp.dao.serviceManage.imp.ServiceManageDaoImp.delete(ServiceManageDaoImp.java:51)
at com.founder.mrp.service.bizLogic.imp.ServiceManageImp.deleteAServiceById(ServiceManageImp.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
org.hibernate.QueryParameterException: could not locate named parameter [id]
q.setParameter("id", id);——————q.setInteger(0, id);//第0个问号传id
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。