我们将Hibernate 3和JBoss 7.0.2与我们的Java应用程序一起使用,并连接到旧的Oracle 9数据库。当应用程序首次启动时,它能够很好地连接到数据库。但是,大约15分钟后,连接开始重置并关闭,JBoss继续尝试使用已关闭的连接。这些是我们看到的错误:
08:37:31,591 WARN JDBCExceptionReporter:71 - SQL错误:17002,SQLState:08006 08:37:31,592 ERROR JDBCExceptionReporter:72 - IO错误:连接重置
07:26:17,839 WARN JDBCExceptionReporter:71 - SQL错误:17008,SQLState:08003 07:26:17,839 ERROR JDBCExceptionReporter:72 - 已关闭连接
standalone.xml中的数据源配置:
<datasource jndi-name="java:/oracleDBOld" pool-name="oracleDBOld" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>
jdbc:oracle:thin:@<host>:<port>:<SID>
</connection-url>
<connection-property name="oracle.jdbc.RetainV9LongBindBehavior">
true
</connection-property>
<driver>
oracle
</driver>
<pool>
<min-pool-size>
0
</min-pool-size>
<max-pool-size>
300
</max-pool-size>
<prefill>
false
</prefill>
<use-strict-min>
false
</use-strict-min>
<flush-strategy>
FailingConnectionOnly
</flush-strategy>
</pool>
<security>
<security-domain>
oracleDBOld-domain
</security-domain>
</security>
<validation>
<check-valid-connection-sql>
select 1 from dual
</check-valid-connection-sql>
<validate-on-match>
false
</validate-on-match>
<background-validation>
false
</background-validation>
<background-validation-millis>
0
</background-validation-millis>
<use-fast-fail>
false
</use-fast-fail>
</validation>
<timeout>
<blocking-timeout-millis>
5000
</blocking-timeout-millis>
<idle-timeout-minutes>
1
</idle-timeout-minutes>
</timeout>
</datasource>
Hibernate配置以编程方式完成:
config = new Configuration();
config.setProperty("hibernate.connection.datasource", (isOldNodeOrDesktop ? "java:comp/env/jdbc/oracleDBOld" : "java:/oracleDBOld"));
config.setProperty("hibernate.show_sql", (isDesktop ? "true" : "false"));
config.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle9Dialect");
config.setProperty("hibernate.query.substitutions", "true 1, false 0");
config.setProperty("hibernate.cache.use_second_level_cache", "true");
config.setProperty("hibernate.cache.use_query_cache", "true");
config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider");
config.setProperty("hibernate.generate_statistics", "false");
config.setProperty("hibernate.cache.use_structured_entries", "false");
// Domain class mappings
config.addClass(com.lmig.requestit.domain.ApplicationGroup.class);
config.addClass(com.lmig.requestit.domain.EIPAGApplication.class);
config.addClass(com.lmig.requestit.domain.EIPAGApplicationEmail.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessApplication.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessApprover.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessLNWUser.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessNode.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessPlatform.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessRole.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessSBU.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessSysgroup.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessUser.class);
config.addClass(com.lmig.requestit.domain.EmergencyAccessUserAccess.class);
config.addClass(com.lmig.requestit.domain.WindowsNode.class);
config.addClass(com.lmig.requestit.domain.UnixNode.class);
// Mapping not aligned with any domain classes; contains SQL
// queries
config.addResource("oldOracleDB_queries.hbm.xml");
// Build SessionFactory
RequestITHibernateOldDBUtils.setSessionFactory(config.buildSessionFactory());
我已经在Hibernate中读到了有关C3P0连接池的信息,但我目前还没有看到它被使用过。我似乎无法弄清楚什么是重置连接。我们的网络人员能够追踪它来自我们的服务器,但我不知道什么会在15分钟后关闭连接,或者为什么它将继续使用封闭连接。任何关于在哪里寻找的提示都会有所帮助。