【问题标题】:Connection to Oracle with Hibernate使用 Hibernate 连接到 Oracle
【发布时间】:2012-06-21 09:56:06
【问题描述】:

我的 Web 应用程序 (Java jsf icefaces - jboss) 使用 hibernate 连接到 Oracle。它工作正常,但如果有一段时间的用户不活动(几个小时),当用户尝试进行查询时,会出现此错误: java.sql.SQLException: Io 异常: Connection reset by peer: socket write error

该应用程序被 3/4 的用户使用,因此打开的连接数量非常少。 我可以解决重启 jboss 服务器的问题。

下面显示了应用程序使用的hibernate.cfg.xml:

<?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="connection.datasource">portaleClientiOracleDS</property> -->       
        <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>   
        <property name="current_session_context_class">thread</property>   
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">Alfre$cost12</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@172.16.216.109:1521:ALFHIST</property>
        <property name="hibernate.connection.username">ALFRESCOST</property>
        <!-- <property name="hibernate.default_catalog">ALFRESCOST</property>-->
        <!-- <property name="hibernate.default_schema">ALFRESCOST</property>-->
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="show_sql">false</property> 
        <property name="use_outer_join">true</property>   
        <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>  

       <property name="c3p0.acquire_increment">1</property>
        <property name="c3p0.idle_test_period">100</property> <!-- seconds -->
        <property name="c3p0.max_size">100</property>
        <property name="c3p0.max_statements">0</property>
        <property name="c3p0.min_size">10</property>
        <property name="c3p0.timeout">100</property> 
        <property name="c3p0.preferredTestQuery">SELECT 1 FROM DUAL</property>
        <property name="c3p0.testConnectionOnCheckout">true</property>

        <mapping resource="it/pillar/accenture/portaleclienti/businesslayer/clienti/dao/hibernate/mappings/StoricoPillar.hbm.xml"/>    

    </session-factory>    
</hibernate-configuration>

我尝试增加 c3p0 的值,但问题仍然存在。任何建议表示赞赏

谢谢

【问题讨论】:

    标签: oracle hibernate sockets jboss icefaces-1.8


    【解决方案1】:

    您可能没有使用 c3p0。 The documentation 说:

    Hibernate 将使用它的 org.hibernate.connection.C3P0ConnectionProvider 如果您设置 hibernate.c3p0.* 属性,则用于连接池。如果你 想用Proxool,参考打包好的hibernate.properties 和 Hibernate 网站了解更多信息。

    以下是 c3p0 的示例 hibernate.properties 文件:

    hibernate.connection.driver_class = org.postgresql.Driver
    hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
    hibernate.connection.username = myuser
    hibernate.connection.password = secret
    hibernate.c3p0.min_size=5
    hibernate.c3p0.max_size=20
    hibernate.c3p0.timeout=1800
    hibernate.c3p0.max_statements=50
    hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
    

    所以属性应该是hibernate.c3p0.xxx 而不是c3p0.xxx

    【讨论】:

    • 感谢您的帖子。不幸的是,它并没有解决问题...我注意到,当用户尝试进行查询时,发生的第一个错误是: java.sql.SQLException: Io exception: Read timed out 然后,如果用户使另一个查询,错误是 java.sql.SQLException: Io exception: Connection reset by peer: socket write error 我快疯了....
    猜你喜欢
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 2016-12-10
    • 2010-12-17
    • 2018-11-22
    • 2018-07-05
    • 2019-05-05
    • 2012-03-23
    相关资源
    最近更新 更多