IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

Connexion timeout entre Hibernate et MySQL


Sujet :

Hibernate Java

  1. #1
    Membre actif Avatar de ploxien
    Inscrit en
    Février 2006
    Messages
    467
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Février 2006
    Messages : 467
    Points : 221
    Points
    221
    Par défaut Connexion timeout entre Hibernate et MySQL
    Hello,

    J'ai un web service que je déploie sur un serveur, sous tomcat 5.

    Ce web service utilise hibernate pour accéder à une base de donnée MySQL.

    Après le déployement, il fonctionne bien, mais si je ne l'utilise pas pendant un certain temps, genre 1 jour, la fois suivante, il me met ce message d'erreur...

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
    MESSAGE: The last packet successfully received from the server was62721 seconds ago.The last packet sent successfully to the server was 62721 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.

    STACKTRACE:

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was62721 seconds ago.The last packet sent successfully to the server was 62721 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.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3246)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    at org.hibernate.loader.Loader.doQuery(Loader.java:674)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2213)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at ch.company.myproject.pro.FraudMessageWithKeywordServiceImpl.fraudMessageWithKeyword(FraudMessageWithKeywordServiceImpl.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
    at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
    at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
    at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3227)
    ... 51 more
    De quoi cela peut-il venir? J'ai lu qu'il faudrait tester la connexion avant de faire une requête?? Je suis un peu perdu...

    Voici mon hibernate.hbm.xml:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    <?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.driver_class">com.mysql.jdbc.Driver</property>
     
     
    		<property name="hibernate.connection.password">password...</property>
     
     
    		<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dbname</property>
     
    		<property name="hibernate.connection.username">root</property>
    		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
     
    		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
     
     
    		<mapping class="ch....
                    ...
     
    		<mapping resource="namedQueries.hbm.xml" />
     
     
    	</session-factory>
     
     
    </hibernate-configuration>
    (\ _ /)
    (='.'=)
    (")-(")
    Deux règles du succès:
    1) Ne communiquez jamais à quelqu'un tout votre savoir...

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 23
    Points : 15
    Points
    15
    Par défaut Re : Connexion timeout entre hibernate et MySQL
    J'ai le même problème,
    j'avais cru comprendre que cela venait du pool de connexion hibernate qui ne doit pas être utilisé en prod car il perd la connexion au bout de quelque chose comme 8 heures d'inactivité et ne sait pas la rétablir (cf doc)

    il faut utiliser quelque chose comme dbcp ou c3po par exemple mais quand j'essaye avec dbcp j'ai toujours le même problème.
    voila ce que j'ai fait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
     
    <!--### Apache DBCP Connection Pool ###-->
    	<!--connection pool-->
    	<property name="hibernate.dbcp.maxActive">10</property>
    	<property name="hibernate.dbcp.whenExhaustedAction">1</property>
    	<property name="hibernate.dbcp.maxWait">20000</property>
    	<property name="hibernate.dbcp.maxIdle">10</property>
     
    	<!-- prepared statement cache-->
    	<property name="hibernate.dbcp.ps.maxActive">10</property>
    	<property name="hibernate.dbcp.ps.whenExhaustedAction">1</property>
    	<property name="hibernate.dbcp.ps.maxWait">20000</property>
    	<property name="hibernate.dbcp.ps.maxIdle">10</property>
     
    	<!-- optional query to validate pooled connections:-->
    	<property name="hibernate.dbcp.validationQuery">select 1</property>
    	<property name="hibernate.dbcp.testOnBorrow">true</property>
    	<property name="hibernate.dbcp.testOnReturn">true</property>
    j'ai aussi ajouté "?autoReconnect=true" a la fin de mon url de connection hibernate et bien sur la librairie "commons-dbcp-1.2.2.jar".

    j'espère que ça fait avancer le débat de mon coté je cherche toujours la solution,
    Merci de votre aide

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 23
    Points : 15
    Points
    15
    Par défaut Re : Connexion timeout entre hibernate et MySQL
    Bonjour,
    n'ayant pas réussit a faire marcher dbcp j'ai testé c3p0 et cela fonctionne du premier coup voici le code que j'ai mis dans mon hibernate.cfg.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     <!-- configuration pool via c3p0-->
            <property name="hibernate.c3p0.acquire_increment">1</property>
            <property name="hibernate.c3p0.idle_test_period">100</property><!-- seconds -->
            <property name="hibernate.c3p0.max_size">100</property><!-- Taille maximale du pool -->
            <property name="hibernate.c3p0.min_size">10</property><!-- Taille minimale du pool -->
            <property name="hibernate.c3p0.timeout">0</property><!-- seconds / 0 =jamais-->
            <property name="hibernate.c3p0.max_statements">0</property><!-- Taille du cache de statements de C3P0. 0 = désactive le cache -->
    + bien sur la lib :c3p0-0.9.1.2.jar.
    Pour ma par ça résout le problème j'espère que cela fonctionnera aussi pour toi ou que cela aidera d'autre personne.
    Cordialement.

  4. #4
    Membre actif Avatar de ploxien
    Inscrit en
    Février 2006
    Messages
    467
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Février 2006
    Messages : 467
    Points : 221
    Points
    221
    Par défaut
    YES!

    Merci, ça marche nickel avec c3p0!!

    A+
    (\ _ /)
    (='.'=)
    (")-(")
    Deux règles du succès:
    1) Ne communiquez jamais à quelqu'un tout votre savoir...

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 18
    Points : 6
    Points
    6
    Par défaut
    Bonjour, j'ai moi aussi le même problème, j'ai essayé en utilisant le pool c3p0 (faut il mettre le autoReconnect=true dans l'url?) comme indiqué ci dessus mais j'ai l'erreur suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
     
    INFO: Illegal access: this web application instance has been stopped already.  Could not load com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
    java.lang.IllegalStateException
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1273)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    	at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1481)
    	at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:32)
    	at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:1964)
    	at java.util.TimerThread.mainLoop(Unknown Source)
    	at java.util.TimerThread.run(Unknown Source)
    Exception in thread "Timer-0" java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$AsyncTestIdleResourceTask
    	at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1481)
    	at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:32)
    	at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:1964)
    	at java.util.TimerThread.mainLoop(Unknown Source)
    	at java.util.TimerThread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    	... 5 more
    Exception in thread "Timer-1" java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$AsyncTestIdleResourceTask
    	at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1481)
    	at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:32)
    	at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:1964)
    	at java.util.TimerThread.mainLoop(Unknown Source)
    	at java.util.TimerThread.run(Unknown Source)
    Exception in thread "Timer-2" java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$AsyncTestIdleResourceTask
    	at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1481)
    	at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:32)
    	at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:1964)
    	at java.util.TimerThread.mainLoop(Unknown Source)
    	at java.util.TimerThread.run(Unknown Source)
    si quelqu'un peut m'aider...

    Merci d'avance

  6. #6
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2005
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 50
    Points : 35
    Points
    35
    Par défaut
    Bonjour,

    Moi aussi, j'ai le même soucis avec hibernate, j'ai des broken pipe.
    je suis sur un linux avec MySQL 5.0.26, hibernate 3.0, jboss 4.2.3.

    j'ai mis la librairie c3p0-0.9.1.2.jar sous %jboss_home%/server/default/lib.
    Le fichier hibernate.cfg.xml se trouve dans un fichier .jar de notre application.
    Dans ce fichier hibernate, il fait référence à une datasource et à des fichiers de mapping.
    d'où ma question, ou je doit mettre les lignes concernant le pool de connexion c3p0 pour qu'il le prenne en compte?

  7. #7
    Membre averti Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Points : 325
    Points
    325
    Par défaut
    Salut les experts

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
      <property name="connection.provider_class">
                     org.hibernate.connection.C3P0ConnectionProvider
            </property>
    dans la configuration de Tisstt, doit on ajouter la class ::: org.hibernate.connection.C3P0ConnectionProvider ?

    Merci


    Citation Envoyé par tisstt Voir le message
    Bonjour,
    n'ayant pas réussit a faire marcher dbcp j'ai testé c3p0 et cela fonctionne du premier coup voici le code que j'ai mis dans mon hibernate.cfg.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     <!-- configuration pool via c3p0-->
            <property name="hibernate.c3p0.acquire_increment">1</property>
            <property name="hibernate.c3p0.idle_test_period">100</property><!-- seconds -->
            <property name="hibernate.c3p0.max_size">100</property><!-- Taille maximale du pool -->
            <property name="hibernate.c3p0.min_size">10</property><!-- Taille minimale du pool -->
            <property name="hibernate.c3p0.timeout">0</property><!-- seconds / 0 =jamais-->
            <property name="hibernate.c3p0.max_statements">0</property><!-- Taille du cache de statements de C3P0. 0 = désactive le cache -->
    + bien sur la lib :c3p0-0.9.1.2.jar.
    Pour ma par ça résout le problème j'espère que cela fonctionnera aussi pour toi ou que cela aidera d'autre personne.
    Cordialement.
    ===================================
    ===Accroche ta charrue à l'Open source===
    ===================================

  8. #8
    Membre à l'essai
    Inscrit en
    Avril 2010
    Messages
    14
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 14
    Points : 24
    Points
    24
    Par défaut
    Bonjour, j'ai le même problème. J'ai utilisé la bibliothèque c3po est sa n'a pas résolu le problème

    j'ai la même config que tisstt et j'ai l'option autoReconnect=true dans ma chaine de connexion:
    <!-- configuration pool via c3p0-->
    <property name="hibernate.c3p0.acquire_increment">1</property>
    <property name="hibernate.c3p0.idle_test_period">100</property><!-- seconds -->
    <property name="hibernate.c3p0.max_size">100</property><!-- Taille maximale du pool -->
    <property name="hibernate.c3p0.min_size">10</property><!-- Taille minimale du pool -->
    <property name="hibernate.c3p0.timeout">0</property><!-- seconds / 0 =jamais-->
    <property name="hibernate.c3p0.max_statements">0</property>
    <!--
    Taille du cache de statements de C3P0. 0 = désactive le cache
    -->
    faut il ajouter:
    <property name="connection.provider_class">
    org.hibernate.connection.C3P0ConnectionProvider
    </property>
    Merci et bonne journée ...

  9. #9
    Membre à l'essai
    Inscrit en
    Avril 2010
    Messages
    14
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 14
    Points : 24
    Points
    24
    Par défaut
    J'essaye de voir avec se blog, espérant que sa corrige le problème

    http://hibernatedb.blogspot.com/2009...ernate-to.html

  10. #10
    Membre régulier Avatar de yacine.dev
    Inscrit en
    Octobre 2009
    Messages
    177
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Octobre 2009
    Messages : 177
    Points : 88
    Points
    88
    Par défaut property name="connection.provider_class"
    J'avais le même problème j'ai ajouté au fichier hibernate.cfg.xml

    <property name="connection.provider_class">
    org.hibernate.connection.C3P0ConnectionProvider
    </property>

    et ça marche

    Merci beaucoup

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'accent entre Hibernate et MySql
    Par nander dans le forum Hibernate
    Réponses: 1
    Dernier message: 25/04/2010, 17h40
  2. Connection entre Hibernate et MySQL
    Par Incinerator dans le forum JDBC
    Réponses: 10
    Dernier message: 19/09/2008, 11h21
  3. connexion entre java et mysql par jdbc odbc
    Par langreth dans le forum JDBC
    Réponses: 11
    Dernier message: 22/04/2008, 23h17
  4. Connexion entre Dreamweaver et Mysql
    Par hoangeric dans le forum Outils
    Réponses: 17
    Dernier message: 08/07/2006, 13h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo