2014-02-07 434 views
0

我使用Hibernate 3.3并知道它与C3P0捆绑在一起。但是在hibernate.cfg.xml中添加C3P0属性设置之后,classnotfound异常出现在控制台中,然后我下载并在我的classpath中添加了c3p0-0.9.1.jar,并且C3P0开始工作。休眠C3P0 unreturnedConnectionTimeout和debugUnreturnedConnectionStackTraces不起作用

现在,当我使用Eclipse添加以下行到我的hibernate.cfg.xml:

<property name="hibernate.c3p0. 

智能感知只显示我:

hibernate.c3p0.acquire_increment 
hibernate.c3p0.idle_test_period 
hibernate.c3p0.max_size 
hibernate.c3p0.max_statements 
hibernate.c3p0.min_size 
hibernate.c3p0.timeout 

它没有显示我unreturnedConnectionTimeoutdebugUnreturnedConnectionStackTraces属性,我仍然复制粘贴这两行,没有任何效果。我没有在服务器日志中随时获取debugUnreturnedConnectionStackTraces。

下面

是我的hibernate.cfg.xml:

<hibernate-configuration> 
<session-factory> 
<property name="hibernate.c3p0.unreturnedConnectionTimeout">40</property> 
<property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces">true</property> 
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property> 
    <property name="hibernate.connection.url">jdbc:oracle:thin:@xyz:1521:sid</property> 
    <property name="hibernate.connection.username">abc</property> 
    <property name="hibernate.connection.password">123</property> 
    <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 
    <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 

    <property name="hibernate.c3p0.min_size">5</property> 
    <property name="hibernate.c3p0.max_size">30</property> 
    <property name="hibernate.c3p0.timeout">20</property> 
    <property name="hibernate.c3p0.max_statements">50</property> 
    <property name="hibernate.c3p0.idle_test_period">3000</property> 

    <property name="hibernate.c3p0.unreturnedConnectionTimeout">40</property> 
    <property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces">true</property> 
</session-factory> 

</hibernate-configuration> 

信息级别转储为:

INFO [org.hibernate.validator.Version] (http--0.0.0.0-8081-3) Hibernate Validator 3.1.0.GA 
INFO [org.hibernate.connection.ConnectionProviderFactory] (http--0.0.0.0-8081-3) Initializing connection provider: org.hibernate.connection.C3P0ConnectionProvider 
INFO [org.hibernate.connection.C3P0ConnectionProvider] (http--0.0.0.0-8081-3) C3P0 using driver: oracle.jdbc.driver.OracleDriver at URL: jdbcracle:thinxyz:1521:abc 
INFO [org.hibernate.connection.C3P0ConnectionProvider] (http--0.0.0.0-8081-3) Connection properties: {user=abcd, password=****, release_mode=after_statement} 
INFO [org.hibernate.connection.C3P0ConnectionProvider] (http--0.0.0.0-8081-3) autocommit mode: false 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) RDBMS: Oracle, version: Oracle Database 11g Release 11.1.0.0.0 - Production 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) JDBC driver: Oracle JDBC driver, version: 10.2.0.5.0 
INFO [org.hibernate.dialect.Dialect] (http--0.0.0.0-8081-3) Using dialect: org.hibernate.dialect.Oracle9Dialect 
WARN [org.hibernate.dialect.Oracle9Dialect] (http--0.0.0.0-8081-3) The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead 
INFO [org.hibernate.transaction.TransactionFactoryFactory] (http--0.0.0.0-8081-3) Using default transaction strategy (direct JDBC transactions) 
INFO [org.hibernate.transaction.TransactionManagerLookupFactory] (http--0.0.0.0-8081-3) No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Automatic flush during beforeCompletion(): disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Automatic session close at end of transaction: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) JDBC batch size: 15 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) JDBC batch updates for versioned data: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Scrollable result sets: enabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) JDBC3 getGeneratedKeys(): disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Connection release mode: after_statement 
WARN [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Overriding release mode as connection provider does not support 'after_statement' 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Default batch fetch size: 1 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Generate SQL with comments: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Order SQL updates by primary key: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Order SQL inserts for batching: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 
INFO [org.hibernate.hql.ast.ASTQueryTranslatorFactory] (http--0.0.0.0-8081-3) Using ASTQueryTranslatorFactory 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Query language substitutions: {} 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) JPA-QL strict compliance: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Second-level cache: enabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Query cache: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Optimize cache for minimal puts: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Structured second-level cache entries: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Statistics: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Deleted entity synthetic identifier rollback: disabled 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Default entity-mode: pojo 
INFO [org.hibernate.cfg.SettingsFactory] (http--0.0.0.0-8081-3) Named query checking : enabled 
INFO [org.hibernate.impl.SessionFactoryImpl] (http--0.0.0.0-8081-3) building session factory 
INFO [org.hibernate.impl.SessionFactoryObjectFactory] (http--0.0.0.0-8081-3) Not binding factory to JNDI, no JNDI name configured 

com.mchange日志:在错误

DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.dialect=org.hibernate.dialect.Oracle9Dialect 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.connection.url=jdbc:oracle:thin:@abcd:1521:xyz 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.connection.username=yyy 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.connection.password=xxx 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.connection.release_mode=after_statement 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.c3p0.min_size=5 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.c3p0.max_size=30 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.c3p0.timeout=20 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.c3p0.max_statements=50 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.c3p0.idle_test_period=3000 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.c3p0.unreturnedConnectionTimeout=40 
DEBUG [org.hibernate.cfg.Configuration] (http--0.0.0.0-8081-1) hibernate.c3p0.debugUnreturnedConnectionStackTraces=true 

com.mchange日志级别:

ERROR [org.hibernate.util.JDBCExceptionReporter] (http--0.0.0.0-8081-1) [email protected] [ connectionPoolDataSource -> [email protected] [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> true, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 31l7yg907o7aar1ysxqrk|22915056, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 20, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> [email protected]  [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 31l7yg907o7aar1ysxqrk|58363f95, jdbcUrl -> jdbc:oracle:thin:@cFRO:1521:ivfrt, properties -> {user=******, password=******, release_mode=after_statement} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 40, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 31l7yg907o7aar1ysxqrk|301c2c35, numHelperThreads -> 3 ] has been closed() -- you can no longer use it. 
TRACE [org.jboss.modules] (http--0.0.0.0-8081-8) Attempting to find resource frro/daos/administration/ in Module "deployment.appname.war:main" from Service Module Loader 
ERROR [stderr] (http--0.0.0.0-8081-1) Error! Please, check your JDBC/JDNI Configurations and Database Server avaliability. 

回答

1

也许这个消息很好,你的应用程序没有连接泄漏。只有当连接被检出时,这些设置才会有明显的效果,但有时候再也不会检入。在一个写得很好的应用程序中,永远不会发生。

尽管如此,请确认设置是“正在采取”。 c3p0在INFO上将其配置转储到池初始化。验证unreturnedConnectionTimeoutdebugUnreturnedConnectionStackTraces是否具有您所期望的值。

c3p0 0.9.1.x很旧。请至少升级到0.9.2.1或最新的0.9.5版本。

一旦您满意您已经调试了任何连接泄漏(或者没有),请禁用debugUnreturnedConnectionStackTraces,这将创建显着的性能拖动。

+0

刚刚添加的信息C3P0初始化从jboss日志转储到我的问题,没有得到像unreturnedConnectionTimeout任何关键字? 谢谢 –

+0

嗨。请配置为让记录器开始com.mchange。*登录INFO。这就是c3p0所在的地方。你只有org.hibernate。*这里。 –

+0

谢谢史蒂夫。你可以请帮忙,如何添加com.mchange。*登录INFO?还有什么要添加到我的hibernate.cfg.xml来获取com.mchange。*日志。我使用jboss作为服务器。 –