-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to configure the lifetime access to the DataBase ?
PostPosted: Wed May 17, 2006 6:26 am 
Newbie

Joined: Wed Apr 19, 2006 2:51 pm
Posts: 16
Dear all,
Here below the complete explanation of the issue I am facing : thanks a lot for any hint that could help me to solve it !
regards,
Laurent

Syntesis :

Architecture : JSF + Hibernate3 on TomCat 5.0.28 ; Hibernate is embedded into JSF through the declaration of an ApplicationScope ManagedBean “HibernateSessionFactory” in faces-config.xml ; “HibernateSessionFactory” is set as a property of another ManagedBean “BeanManager” responsible for the execution of the queries into the data base. Finally, “BeanManager” is set as a property of another ManagedBean “actionBean” responsible to execute the actions from the User Interface.

By the way we have a kind of Dependency Injection through the initializing of JSF :
HibernateSessionFactory => BeanManager => ActionBean

faces-config.xml :

<faces-config>

<managed-bean>
<managed-bean-name>hibernateSessionFactory</managed-bean-name>
<managed-bean-class>bsa.integration.HibernateSessionFactoryImpl</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>beanManager</managed-bean-name>
<managed-bean-class>bsa.integration.service.beanManager</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
<managed-property>
<property-name>sessionFactory</property-name>
<property-class>bsa.integration.HibernateSessionFactory</property-class>
<value>#{hibernateSessionFactory}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>actionBean</managed-bean-name>
<managed-bean-class>bsa.view.jsfBeans.ActionBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>beanManager</property-name>
<property-class> bsa.integration.service.beanManager </property-class>
<value>#{beanManager}</value>
</managed-property>
</managed-bean>

</faces-config>


EVERYTHING WORKS FINE, except …

Issue :

AFTER A LONG TIME of inactivity (night time for instance), the application is still running on TomCat and the Login page (redirect from index.jsp) is normally displayed but the data base can’t be accessed anymore ; IT SEEMS THAT HIBERNATE DOES NOT ENABLE ANYMORE CONNECTION TO THE DATABASE.

QUESTION : What is to be configured to manage correctly the lifetime of the access to the DataBase ?

After reloading or restarting the application in TomCat, it works fine again …

ANY IDEA OF WHAT I COULD DO TO SOLVE THIS ?


TomCat Log :

Caused by: javax.faces.el.EvaluationException: org.hibernate.exception.JDBCConnectionException: could not execute query
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:130)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
... 34 more

...

Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
...


** END NESTED EXCEPTION **
Last packet sent to the server was 11 ms ago.
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2710)

...

2006-05-16 09:35:05 StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.FacesException: Error calling action method of component with id formLogin:actionLoginId
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)

Caused by: javax.faces.el.EvaluationException: org.hibernate.exception.JDBCConnectionException: could not execute query
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:130)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
... 34 more


HibernateSessionFactoryImpl :

public class HibernateSessionFactoryImpl implements HibernateSessionFactory {

static Log log = LogFactory.getLo(HibernateSessionFactoryImpl.class);

static final SessionFactory sessionFactory ;

static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal threadLocal = new ThreadLocal();

public Session getSession() {
Session s = (Session) threadLocal.get();
// Open a new Session, if this Thread has none yet
if (s == null) {

//Create the Hibernate session
s = sessionFactory.openSession();
//Set the Hibernate session in this Thread ;
threadLocal.set(s);
}
return s;
}


Hibernate.cfg.xml :

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dmexmanager</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<mapping resource = … />

</hibernate-configuration


web.xml :

<web-app>

<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>

_________________
Cheers,
Laurent

Thanks for rating in case it helped !


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 7:21 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hello,

this is a frequent topic. look for mysql reconnect or "release mode" in the forum.
You are using the Hibernate Session pool what is not recommend for production use. Set up a connection pool in Tomcat and use this one.

Best Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.