Data Source - Jboss - Hibernate

Using datasource to connect database

I hosted  Java web app with MySQL database in Jboss server. When every morning  I see it database connection was lost.Then I ran a query to see timeout variables.
wait_timout = 28800

28800 = 8 hours.

If there is no request comes after 8 hours  connection will be lost. I tried several solution for this.After using datasource to connect database that problem was solved.


<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: mysql-ds.xml 41017 2006-02-07 14:26:14Z acoliver $ -->
<!--  Datasource config for MySQL using 3.0.9 available from:

    <!-- should only be used on drivers after 3.22.1 with "ping" support
    <!-- sql to call when connection is created
    <new-connection-sql>some arbitrary sql</new-connection-sql>
    <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>

    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
 <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.datasource">java:myDataSource</property>
        <!--<mapping class="com.sameera.domain.User" />-->

mysql-ds.xml file is taken from jboss server.. jboss-5.1.0.GA\docs\examples\jca
'myDataSource' is the name of datasource

I put mysql-connector-java-5.1.5-bin.jar  to the jboss-5.1.0.GA\server\default\lib

No comments:

Post a Comment