DaoLayer代碼是:拋出:IllegalArgumentException:在查詢中沒有位置參數
String query="from hibernate.EmpRecord u where u.uname=? and u.upass=?";
Query hql =session.createQuery(query);
hql.setString(0, uname);
hql.setString(1, upass);
List<EmpRecord> userObjs= hql.list();
if(userObjs.size() != 0) {
System.out.println(" User name : " + userObjs.get(0).getuname() + ", Status : " + userObjs.get(0).getIs_admin());
userStatus = true;
}
transaction.commit();
System.out.println(userStatus);
} catch(Exception e) {
e.printStackTrace();
transaction.rollback();
}
return userStatus;
}
堆棧跟蹤是:
inside Process Method
Inside into service class
Inside into dao class
java.lang.IllegalArgumentException: No positional parameters in query: from hibernate.EmpRecord u where u.uname=? and u.upass=?
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:356)
at org.hibernate.impl.AbstractQueryImpl.setString(AbstractQueryImpl.java:481)
at hibernate.EmpDao.verifyUserDaoAndPassDao(EmpDao.java:32)
at service.Empservice.verifyUserNameAndPassword(Empservice.java:20)
at web.LogController.processCredentials(LogController.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
也許嘗試在查詢中使用空格= u.uname =?和u.upass =? –