这是代码:
public Users login(String username) {
Users user=null;
try {
String hql="select user.name,user.password from Users user where user.name=:name";
Query query = session.createQuery(hql);
query.setString("name", username);
user=(Users) query.list().get(0);
} catch (HibernateException e) {
e.printStackTrace();
}
return user;
}
错误:</p>
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.xl.entity.Users
at com.xl.impl.HouseDaoImpl.login(HouseDaoImpl.java:51)
at com.xl.biz.HouseBiz.login(HouseBiz.java:25)
at com.xl.Servlet.UserServlet.doGet(UserServlet.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
(翻译由谷歌翻译提供)