2012-08-27 171 views
0

我想用C3P0設置,以使應用程序能夠自動丟棄陳舊的連接,並重新建立連接automatically.I已設置的配置屬性爲下文sessionfactoryprovider類:休眠C3P0問題

configuration.setProperty("hibernate.c3p0.min_size", c3p0 
       .get("minPoolSize") != null ? c3p0.get("minPoolSize") 
       : "1"); 
configuration.setProperty("hibernate.c3p0.max_size", c3p0 
       .get("maxPoolSize") != null ? c3p0.get("maxPoolSize") 
       : "50"); 
configuration.setProperty("hibernate.c3p0.timeout", c3p0 
       .get("maxIdleTime") != null ? c3p0.get("maxIdleTime") 
       : "900"); 
configuration.setProperty(
       "hibernate.c3p0.acquireRetryAttempts", 
       c3p0.get("acquireRetryAttempts") != null ? c3p0 
           .get("acquireRetryAttempts") : "30"); 
configuration.setProperty(
       "hibernate.c3p0.acquireIncrement", 
       c3p0.get("acquireIncrement") != null ? c3p0 
           .get("acquireIncrement") : "5"); 
configuration.setProperty(
       "hibernate.c3p0.idleConnectionTestPeriod", 
       c3p0.get("idleConnectionTestPeriod") != null ? c3p0 
           .get("idleConnectionTestPeriod") : "60"); 
configuration.setProperty("hibernate.c3p0.initialPoolSize", c3p0 
       .get("minPoolSize") != null ? c3p0.get("minPoolSize") 
       : "1"); 
configuration.setProperty(
       "hibernate.c3p0.maxStatements", 
       c3p0.get("maxStatementsPerConnection") != null ? c3p0 
           .get("maxStatementsPerConnection") 
           : "0"); 
configuration.setProperty("preferredTestQuery", "select 1 from dual"); 
configuration.setProperty("hibernate.c3p0.testConnectionOnCheckin", 
       "true"); 
configuration.setProperty("hibernate.c3p0.testConnectionOnCheckout", 
       "true"); 
configuration.setProperty("testConnectionOnCheckin", "true"); 
configuration.setProperty("hibernate.c3p0.preferredTestQuery", 
       "select 1 from dual"); 

我沒有在應用程序中發現任何日誌,試圖執行測試查詢,也沒有在數據庫重新啓動後恢復。 「show_sql」在屬性文件中設置爲true,在日誌中,我可以看到其他查詢正在執行。
包裝版本如下: C3P0 = 0.9.1.2; HibernateAnnotations = 3.3; Hibernate = 3.3;

有人可以請建議我應該如何去調試呢?

回答

0

嘗試設置的日誌記錄級別C3P0在你的log4j的配置調試:

log4j.category.com.mchange=DEBUG 
+0

至於建議,我已經設置了日誌級別爲DEBUG。我可以在「SessionFactory」中看到所有這些屬性。但是,查詢仍然沒有按照定期的時間間隔執行。 – user1269701

+0

它使用您的設置?檢查屬性名稱是否正確,並確認C3P0確實在使用您的設置。上次我設置c3p0時,配置屬性名稱中出現了一些奇怪現象(「hibernate.c3p0。」與「without」)。我最終直接在Spring configuration-xml中將值設置爲C3P0的ComboPooledDataSource,這似乎解決了這個問題。 – esaj

+0

非常感謝您的建議,設置日誌級別進行調試。這有助於找出問題的根源。事實證明,我根本沒有使用c3p0ConnectionProvider。其他一些連接提供程序被設置爲默認值,因此它們的權限沒有得到提升 – user1269701