开发者社区> 问答> 正文

hibernate delete语句报QueryParameterException错误

代码:

 @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)

展开
收起
云栖技术 2016-06-02 13:48:56 2621 0
1 条回答
写回答
取消 提交回答
  • 社区爱好者,专为云栖社区服务!

    org.hibernate.QueryParameterException: could not locate named parameter [id]
    q.setParameter("id", id);——————q.setInteger(0, id);//第0个问号传id

    2019-07-17 19:24:45
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spark SQL: Past, Present and Future 立即下载
Spark SQL:Past Present &Future 立即下载
低代码开发师(初级)实战教程 立即下载