【问题标题】:SQL closed Connection - need to increase timeout?SQL关闭连接 - 需要增加超时?
【发布时间】:2017-05-24 21:33:10
【问题描述】:

连接到我的Oracle 数据库时,我的Java 应用程序中出现“SQL 关闭连接”。

我是否需要增加我的超时时间或对我的 XML 配置进行任何其他更改?

下面是我的persistence.xml 文件:

 <persistence-unit name="mypersistenceUnit">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>com.my.package.entities.Person</class>
        <class>com.my.package.entities.Address</class>

        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
            <property name="hibernate.connection.provider_class" value="org.hibernate.c3p0.internal.C3P0ConnectionProvider"/>
            <property name="hibernate.c3p0.max_size" value="1"/>
            <property name="hibernate.c3p0.min_size" value="1"/>
            <property name="hibernate.c3p0.acquire_increment" value="2"/>
            <property name="hibernate.c3p0.idle_test_period" value="300"/>
            <property name="hibernate.c3p0.max_statements" value="15"/>
            <property name="hibernate.c3p0.timeout" value="0"/>
            <property name="hibernate.c3p0.unreturnedConnectionTimeout" value="30000"/>
            <property name="hibernate.c3p0.dataSourceName" value="mypersistenceUnit JPA"/>
            <property name="hibernate.jdbc.fetch_size" value="50"/>
            <property name="hibernate.default_batch_fetch_size" value="10"/>
        </properties>
    </persistence-unit>

【问题讨论】:

    标签: java xml oracle hibernate c3p0


    【解决方案1】:

    也许 Oracle 为您提供的连接最终会超时或过期(尽管您已配置空闲连接测试)。在任何情况下,您的连接测试可能会更严格,在每五分钟一次的空闲测试之间中断的连接将移交给中断的客户端,这可能会引发您的异常。

    我会添加

    <property name="hibernate.c3p0.testConnectionOnCheckout" value="true"/>
    

    看看这是否不能解决问题。另见c3p0's docs

    【讨论】:

      猜你喜欢
      • 2021-09-06
      • 2013-08-15
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 2018-04-17
      • 2016-05-08
      • 1970-01-01
      相关资源
      最近更新 更多