2010-06-15 4 views
2

J'ai lu tant d'articles sur Internet à propos de ce problème, mais aucun ne semble avoir une solution claire. S'il vous plaît quelqu'un pourrait-il me donner une réponse définitive quant à pourquoi je reçois des délais d'attente de base de données. L'application est une application GWT hébergée sur un serveur Tomcat 5.5. J'utilise le printemps et l'usine de session est créée dans le applicationContext.xml comme suitDélai de connexion à la base de données

<bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">${connection.dialect}</prop> 
      <prop key="hibernate.connection.username">${connection.username}</prop> 
      <prop key="hibernate.connection.password">${connection.password}</prop> 
      <prop key="hibernate.connection.url">${connection.url}</prop> 
      <prop key="hibernate.connection.driver_class">${connection.driver.class}</prop> 
      <prop key="hibernate.show_sql">${show.sql}</prop> 
      <prop key="hibernate.hbm2ddl.auto">update</prop> 
      <prop key="hibernate.c3p0.min_size">5</prop> 
      <prop key="hibernate.c3p0.max_size">20</prop> 
      <prop key="hibernate.c3p0.timeout">1800</prop> 
      <prop key="hibernate.c3p0.max_statements">50</prop> 
      <prop key="hibernate.c3p0.idle_test_period">300</prop> 
     </props> 
    </property> 
    <property name="annotatedClasses"> 
     <list> 
      <value>za.co.xxxx.traintrack.server.model.Answer</value> 
      <value>za.co.xxxx.traintrack.server.model.Company</value> 
      <value>za.co.xxxx.traintrack.server.model.CompanyRegion</value> 
      <value>za.co.xxxx.traintrack.server.model.Merchant</value> 
      <value>za.co.xxxx.traintrack.server.model.Module</value> 
      <value>za.co.xxxx.traintrack.server.model.Question</value> 
      <value>za.co.xxxx.traintrack.server.model.User</value> 
      <value>za.co.xxxx.traintrack.server.model.CompletedModule</value> 
     </list> 
    </property> 
</bean> 

<bean id="dao" class="za.co.xxxx.traintrack.server.DAO"> 
    <property name="sessionFactory" ref="sessionFactory"/> 
    <property name="adminUsername" value="${admin.user.name}"/> 
    <property name="adminPassword" value="${admin.user.password}"/> 
    <property name="godUsername" value="${god.user.name}"/> 
    <property name="godPassword" value="${god.user.password}"/> 
</bean> 

Tout fonctionne très bien untile le lendemain:

INFO | jvm 1 | 2010/06/15 14:42:27 | 2010-06-15 18:42:27,804 WARN 
[JDBCExceptionReporter] : SQL Error: 0, SQLState: 08S01 
INFO | jvm 1 | 2010/06/15 14:42:27 | 2010-06-15 18:42:27,821 ERROR 
[JDBCExceptionReporter] : The last packet successfully received from the server 
was 38729 seconds ago.The last packet sent successfully to the server was 38729 
seconds ago, which is longer than the server configured value of 'wait_timeout'. 
You should consider either expiring and/or testing connection validity before 
use in your application, increasing the server configured values for client 
timeouts, or using the Connector/J connection property 'autoReconnect=true' to 
avoid this problem. 
INFO | jvm 1 | 2010/06/15 14:42:27 | Jun 15, 2010 6:42:27 PM 
org.apache.catalina.core.ApplicationContext log 
INFO | jvm 1 | 2010/06/15 14:42:27 | SEVERE: Exception while dispatching 
incoming RPC call 

J'ai lu tant de choses différentes (dont aucune travaillé), s'il vous plaît aider

+1

Quelles choses avez-vous essayé? Le message d'erreur est à savoir déjà toute la réponse à son propre. – BalusC

+0

Mais pourquoi le 'hibernate.c3p0.idle_test_period' semble-t-il être ignoré? Cette trace est-elle générée par le code en utilisant C3P0? –

+0

Votre message d'erreur indique que le serveur de base de données était inaccessible depuis * onze heures *. Êtes-vous vraiment sûr que vous avez même eu une connexion réseau pendant la nuit? –

Répondre

1

Regardez ce lien http://www.databasesandlife.com/automatic-reconnect-from-hibernate-to-mysql/

In “hibernate.cfg.xml”: 

<!-- hibernate.cfg.xml --> 
<property name="c3p0.min_size">5</property> 
<property name="c3p0.max_size">20</property> 
<property name="c3p0.timeout">1800</property> 
<property name="c3p0.max_statements">50</property> 
<property name="connection.provider_class"> 
    org.hibernate.connection.C3P0ConnectionProvider</property> 
<!-- no "connection.pool_size" entry! --> 

T alors créez un fichier "c3p0.properties" qui doit être dans la racine du classpath (c.-à-d. aucun moyen de passer outre pour certaines parties de l'application):

# c3p0.properties 
c3p0.testConnectionOnCheckout=true 
+0

Romain, j'ai trouvé cet article la semaine dernière et j'ai essayé le fichier c3p0.properties sans chance, mais je n'ai pas ajouté la connexion propriété .provider_class, donc je vais réessayer ce soir –

+0

@Clinton Bosch laissez-nous savoir comment cela fonctionne. Assurez-vous également de mettre les propriétés exactes comme indiqué dans le message. Si cela fonctionne, vous pouvez modifier plus tard. –

+0

Romain, malheureusement cela ne fonctionne pas pour moi, la connexion est encore expirée. –

0

Romain, je n'ai pas hibernate.cfg.xml (tout fait dans applicationContext.xml)

c3p0.properties

c3p0.testConnectionOnCheckout=true 

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xsi:schemaLocation=" 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-2.5.xsd 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
      "> 

    <context:annotation-config/> 

    <context:component-scan base-package="za.co.cmsoftware.traintrack.server"/> 

    <!-- Application properties --> 
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>file:${user.dir}/@[email protected]</value> 
      </list> 
     </property> 
    </bean> 

    <bean id="sessionFactory" 
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">${connection.dialect}</prop> 
       <prop key="hibernate.connection.username">${connection.username}</prop> 
       <prop key="hibernate.connection.password">${connection.password}</prop> 
       <prop key="hibernate.connection.url">${connection.url}</prop> 
       <prop key="hibernate.connection.driver_class">${connection.driver.class}</prop> 
       <prop key="hibernate.show_sql">${show.sql}</prop> 
       <prop key="hibernate.hbm2ddl.auto">update</prop> 
       <prop key="hibernate.c3p0.min_size">5</prop> 
       <prop key="hibernate.c3p0.max_size">20</prop> 
       <prop key="hibernate.c3p0.timeout">1800</prop> 
       <prop key="hibernate.c3p0.max_statements">50</prop> 
       <prop key="hibernate.c3p0.idle_test_period">300</prop> 
       <prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> 
      </props> 
     </property> 
     <property name="annotatedClasses"> 
      <list> 
       <value>za.co.xxxx.traintrack.server.model.Answer</value> 
       <value>za.co.xxxx.traintrack.server.model.Company</value> 
       <value>za.co.xxxx.traintrack.server.model.CompanyRegion</value> 
       <value>za.co.xxxx.traintrack.server.model.Merchant</value> 
       <value>za.co.xxxx.traintrack.server.model.Module</value> 
       <value>za.co.xxxx.traintrack.server.model.Question</value> 
       <value>za.co.xxxx.traintrack.server.model.User</value> 
       <value>za.co.xxxx.traintrack.server.model.CompletedModule</value> 
      </list> 
     </property> 
    </bean> 

    <bean id="dao" class="za.co.xxxx.traintrack.server.DAO"> 
     <property name="sessionFactory" ref="sessionFactory"/> 
     <property name="adminUsername" value="${admin.user.name}"/> 
     <property name="adminPassword" value="${admin.user.password}"/> 
     <property name="godUsername" value="${god.user.name}"/> 
     <property name="godPassword" value="${god.user.password}"/> 
    </bean> 

    <bean id="transactionManager" 
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory"> 
      <ref local="sessionFactory"/> 
     </property> 
    </bean> 

    <!-- enable the configuration of transactional behavior based on annotations --> 
    <tx:annotation-driven transaction-manager="transactionManager"/> 

</beans> 
Questions connexes