erictamlam
erictamlam
2015-04-27 03:24

hibernate delete语句报QueryParameterException错误

  • hibernate
  • delete

代码:

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

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答