Topic: 关于hibernate的错误,会的朋友看看,谢谢先 |
Print this page |
1.关于hibernate的错误,会的朋友看看,谢谢先 | Copy to clipboard |
Posted by: death0320 Posted on: 2004-10-25 08:55 软件环境: hibernate+struts App server:tomcat Database:mysql IDE:eclispe3.0.1+myeclispe3.8GA 配置文件: <hibernate-mapping package="test.myalbum.db"> <class name="Users" table="users"> <id name="userid" column="USERID" type="java.lang.String"> <generator class="assigned"/> </id> <property name="userpass" column="USERPASS" type="java.lang.String" /> <property name="username" column="USERNAME" type="java.lang.String" /> <property name="sex" column="SEX" type="java.lang.String" /> <property name="birthday" column="BIRTHDAY" type="java.lang.String" /> <property name="email" column="EMAIL" type="java.lang.String" /> <property name="phone" column="PHONE" type="java.lang.String" /> <property name="mobile" column="MOBILE" type="java.lang.String" /> <property name="address" column="ADDRESS" type="java.lang.String" /> <property name="question" column="QUESTION" type="java.lang.String" /> <property name="answer" column="ANSWER" type="java.lang.String" /> <property name="interest" column="INTEREST" type="java.lang.String" /> <property name="remark" column="REMARK" type="java.lang.String" /> <property name="isvip" column="ISVIP" type="java.lang.String" /> <property name="diskspace" column="DISKSPACE" type="java.lang.String" /> </class> </hibernate-mapping> 错误提示信息: jsp页面上报的错: exception javax.servlet.ServletException org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) test.myalbum.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:103) root cause java.lang.NullPointerException test.myalbum.actions.LogonAction.execute(LogonAction.java:59) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) test.myalbum.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:103) tomcat上报的错: net.sf.hibernate.HibernateException: Session is closed at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3283) at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.j ava:65) at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:704) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:185) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections (Loader.java:133) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:836) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:856) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51) at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java: 419) at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2106) at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1980 ) at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1909) at test.myalbum.util.HibernateUtil.findById(HibernateUtil.java:60) at test.myalbum.daoimpl.UsersDAOImpl.findUserById(UsersDAOImpl.java:43) at test.myalbum.bo.UsersManager.findUsersById(UsersManager.java:51) at test.myalbum.actions.LogonAction.execute(LogonAction.java:5 at org.apache.struts.action.RequestProcessor.processActionPerform(Reques tProcessor.java:484) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja va:274) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:148 2) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at javax.servlet.http.HttpServlet.service(HttpServlet.java:810) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:157) at test.myalbum.util.SetCharacterEncodingFilter.doFilter(SetCharacterEnc odingFilter.java:103) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:186) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV alve.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv eContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a:520) at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard ContextValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV alve.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv eContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j ava:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv eContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j ava:117) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv eContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal ve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv eContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16 0) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java :793) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce ssConnection(Http11Protocol.java:702) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java :571) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP ool.java:644) at java.lang.Thread.run(Thread.java:534) 你的分析: 这是个很平常的登录验证,用的是根据userid在数据库中查出一个对象,然后用form上的值和查出来的做比较。我在做对hibernate的操作时,在CURD操作中,都在finally块用使用了session.close();这样对吗?现在问题是当tomcat刚刚起动后,登录没有问题,可以被登录成功,但当我后退回登录页的时候,再登录时,就报了以上的错误。这和查询完就session.close()有关系吗?我觉得应该用完就关掉的。请大家看看错在哪里了,研究了一个晚上,都没觉得有什么问题,可就是报错。 查询的代码是: public static Object findById(Class cls, String id) throws HibernateException { Object obj = null; Session session = HibernateSessionFactory.currentSession(); try { obj = session.load(cls, id); } catch(HibernateException he) { throw he; } finally { session.flush(); session.close(); } return obj; } |
2.Re:关于hibernate的错误,会的朋友看看,谢谢先 [Re: death0320] | Copy to clipboard |
Posted by: gispda Posted on: 2004-10-26 23:58 肯定是了, 不知道你的currentSession()如何写的? 应该有再打开一个session的语句吧. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |