日期:2014-05-18  浏览次数:20720 次

HQL 删除问题
HibernateUtil   hibera=new   HibernateUtil();
                          Session   session=hibera.currentSession();
                          Transaction   tx=session.beginTransaction();
                String     id   =(String)   request.getParameter( "plane_id ");
                String   sql= "delete   Plane   p   where   p.id=id   ";
                Query   query   =   session.createQuery(sql);
                query.executeUpdate();
                tx.commit();
           
执行后报
hibernate.QueryException:   query   must   begin   with   SELECT   or   FROM:   delete   [delete   ems.hibernate.Plane   p   where   p.id=id   ]
at   org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:83)
at   org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:108)
at   org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:28)
at   org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:191)
at   org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:167)
at   org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:75)
at   org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:54)
at   org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at   org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at   org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at   org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
at   ems.struts.DeletePlaneAction.execute(DeletePlaneAction.java:25)
at   org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at   org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at   javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at   javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at   weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1072)
at   weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at   weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
at   weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6981)
at   weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at   weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at   weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3892)
at   weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2766)
at   weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at   weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)