zoukankan      html  css  js  c++  java
  • Hibernate连接数据库超时设置autoReconnect=true

    如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat. 

        不用hibernate的话, connection url加参数: autoReconnect=true 


        用hibernate的话, 加如下属性: 

            <property name="connection.autoReconnect">true</property> 
            <property name="connection.autoReconnectForPools">true</property> 
            <property name="connection.is-connection-validation-required">true</property> 


        要是还用c3p0连接池: 

            <property name="hibernate.c3p0.acquire_increment">1</property> 
            <property name="hibernate.c3p0.idle_test_period">0</property> 
            <property name="hibernate.c3p0.timeout">0</property> 
            <property name="hibernate.c3p0.validate">true</property>
    <!-- 指定Hibernate的配置文件 -->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="hibernateProperties">    
    <props>    
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>    
    <prop key="hibernate.show_sql">true</prop>    
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>    
    <prop key="hibernate.autoReconnect">true</prop>
    <prop key="hibernate.autoReconnectForPools">true</prop>
    <prop key="hibernate.is-connection-validation-required">true</prop>
    <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
    <prop key="hibernate.c3p0.min_size">8</prop>
    <prop key="hibernate.c3p0.max_size">200</prop>
    <prop key="hibernate.c3p0.timeout">600</prop>
    <prop key="hibernate.c3p0.max_statements">0</prop>
    <prop key="hibernate.c3p0.idle_test_period">60</prop>
    <prop key="hibernate.c3p0.acquire_increment">2</prop>
    <prop key="hibernate.c3p0.validate">true</prop>
    </props>    
    </property>
    <property name="configLocation"
    value="classpath:hibernate.cfg.xml">
    </property>
  • 相关阅读:
    单例模式的三种写法
    ASP.NET如何下载大文件
    字符串是引用类型
    SQL 事务隔离级别
    Sql Server 锁
    设非主键为聚集索引
    C#如何使用SqlCacheDependency
    简易系统后台架构
    matlab cross 3*1 向量叉乘
    Matlab求齐次方程的解
  • 原文地址:https://www.cnblogs.com/hwaggLee/p/5519361.html
Copyright © 2011-2022 走看看