-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: JDBC Exception , if no activity for 4-5 hours
PostPosted: Tue Jan 31, 2006 11:53 pm 
Newbie

Joined: Tue Oct 04, 2005 1:35 am
Posts: 12
Hello guys,
After leaving the server on for more than 4-5 hrs without doing any activity, from the web browser trying to login gives a JDBC exception on the server. Can anybody please tell me the reason for this? if no activity is done then why hibernate crashes the application? Its a critical issue for me. please reply.. Thanx in advance



Hibernate version: 3.0

Mapping documents:<!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="show_sql">false</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/mforms</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>

<mapping resource="hbm/xml/Tag.hbm.xml"/>
<mapping resource="hbm/xml/Groups.hbm.xml"/>
<mapping resource="hbm/xml/Users.hbm.xml"/>
<mapping resource="hbm/xml/Role.hbm.xml"/>
<mapping resource="hbm/xml/UserRole.hbm.xml"/>
<mapping resource="hbm/xml/UserGroup.hbm.xml"/>
<mapping resource="hbm/xml/Form.hbm.xml"/>
<mapping resource="hbm/xml/FormTag.hbm.xml"/>

<mapping resource="hbm/xml/ProcessConnectorMapping.hbm.xml"/>

</session-factory>
</hibernate-configuration>



Code between sessionFactory.openSession() and session.close():
public class HibernateUtils {

private static Log log = LogFactory.getLog(HibernateUtils.class);

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal session = new ThreadLocal();
/**
* used to get hibernate session
* @return Session
* @throws HibernateException
*/
public static Session currentSession() throws HibernateException {
Session s = sessionFactory.openSession();
session.set(s);
return s;
}

/**
* used to close session
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();

if (s != null)
s.close();
session.set(null);
}

}


Full stack trace of any exception that occurs:
at com.mysql.jdbc.Connection.checkClosed(Connection.java:2470)
at com.mysql.jdbc.Connection.commit(Connection.java:1141)
at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JD
BCTransaction.java:119)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java
:95)
at com.danucom.mforms.webapp.adapter.HibernateAdapter.commitTransaction(
HibernateAdapter.java:215)
at com.danucom.mforms.webapp.util.DatabaseUtil.userLogin(DatabaseUtil.ja
va:101)
at com.danucom.mforms.webapp.servicebean.LoginBean.submit(LoginBean.java
:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)

at com.sun.faces.application.ActionListenerImpl.processAction(ActionList
enerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:266)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:3
80)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicat
ionPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
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:118)
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
:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Thread.java:595)
com.danucom.mforms.webapp.adapter.HibernateAdapter 2006-01-31 22:31:01,218 -- FA
TAL -- org.hibernate.TransactionException: JDBC commit failed


Name and version of the database you are using: MySQL 5

The generated SQL (show_sql=true): NA

Debug level Hibernate log excerpt:NA


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 9:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Sounds like you need to enable connection validation on your connection pool.

And by the way, with that config you are using Hibernate's built-in connection pooling mechanism (the thing that dumps the big warning you see when you start the SessionFactory about it not being intended for production purposes).

http://www.hibernate.org/hib_docs/v3/re ... ernatejdbc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 11:38 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
Changing the url to
Code:
jdbc:mysql://localhost/mforms?autoReconnect=true

might be enough


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 11:42 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
You asked the reason - the db connections have all gone stale - i.e. timed out on the mysql server, or in a firewall somewhere, so the tomcat (I guess?) is holding connections that the DB will no longer honor. I think the autoreconnect will reestablish the connect for you though but make note of Steve's point.

It can't be too critical though if you're having no activity for 5 hours ;o)
(Sorry, couldn't help it...)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.