Hi HybernateUsers,
I am getting a strange problem with hybernate and mysql.
Description of error:
org.hibernate.SessionException: Session was already closed org.hibernate.impl.SessionImpl.close(SessionImpl.java:275) sun.reflect.GeneratedMethodAccessor82.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301) $Proxy48.close(Unknown Source) com.schneider.innovativeideas.DBOperations.CDBOperations.getCostCenters(CDBOperations.java:235) org.apache.jsp.IIL_005fAdminIdeaListUI_jsp._jspService(org.apache.jsp.IIL_005fAdminIdeaListUI_jsp:148) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
. In my.int ,I have set wait_timeout as 259200(3 days). I should get this exception if i didnt send any request for 3 days.But i am using this app continously even though after 3 days i am getting this error.
This is where I am getting this error. try{ oSession = getDBSession(); Transaction tx = oSession.beginTransaction(); Query q = oSession.createQuery("from CCostCentre"); System.out.println("------------afterquery"+q.list()); costCentres = (List) q.list(); System.out.println("-------------costCentres>"+costCentres.size()); } catch (Exception e) { e.printStackTrace(); System.out.println("----------------->ExceptionCostCenter"); oSession.close(); }
And my hybernate.cfg file is as follows.
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/innovativeideas </property> <property name="connection.driver_class">com.mysql.jdbc.Driver </property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">Nagendra_72</property>
<!-- SQL dialect --> <property name="dialect"> org.hibernate.dialect.DerbyDialect </property>
<!-- Debug logging of SQL statements --> <property name="show_sql">false</property> <property name="hibernate.cache.use_query_cache"> false </property> <property name="hibernate.cache.use_second_level_cache"> false </property> <property name="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </property>
<!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property>
<!-- Mapping Files -->
<mapping resource="com/schneider/innovativeideas/DBOperations/CInnovativeIdea.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CSegment.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CIdeaState.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CUser.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CReviewRequest.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CIdeaReviewRecord.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CNews.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CCostCentre.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CIdeaStatesPEB.hbm.xml" /> <mapping resource="com/schneider/innovativeideas/DBOperations/CComments.hbm.xml" />
</session-factory> </hibernate-configuration>
My hybernateutil.java is as follows:
{ // Create the SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); ex.printStackTrace(); throw new ExceptionInInitializerError(ex); } }
Can any one Please look into the problem and guide me what to do to fix this problem like do i need to add c3p0 stuff as i missed it in my cfg file or any other suggestion...
Thanks for ur help Ganesh
|