Minha configuração do Hibernate:
hibernateConfig = new AnnotationConfiguration();
hibernateConfig.setProperty("hibernate.dialect", props.getString("hibernate.dialect"));
hibernateConfig.setProperty("hibernate.connection.driver_class", driver);
hibernateConfig.setProperty("hibernate.connection.url", url);
hibernateConfig.setProperty("hibernate.connection.username", user);
hibernateConfig.setProperty("hibernate.connection.password", pass);
hibernateConfig.setProperty("hibernate.hbm2ddl.auto", props.getString("hibernate.hbm2dll.auto"));
hibernateConfig.setProperty("hibernate.show_sql", props.getString("hibernate.show_sql"));
// c3p0
hibernateConfig.setProperty("hibernate.c3p0.acquire_increment", "1");
hibernateConfig.setProperty("hibernate.c3p0.idle_test_period", "300");
hibernateConfig.setProperty("hibernate.c3p0.timeout", "120");
//hibernateConfig.setProperty("hibernate.c3p0.max_size","4"); // ATTENTION: This line will make hibernate go crazy, missing criterias selections like
// the row was not even there. Yes I love Hibernate! Uncomment and run the tests to find
// out for yourself. Basically if you call UserDAO.findByUsername in a row, the first time
// it works, the second time it returns null. It is like the first criteria selection is
// removing the record from the database.
hibernateConfig.setProperty("hibernate.c3p0.min_size", "1");
hibernateConfig.setProperty("hibernate.c3p0.max_statement", "0");
hibernateConfig.setProperty("hibernate.c3p0.preferredTestQuery", "select 1;");
Depois de um tempo, irremediavelmente eu recebo:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during rollback(). Transaction resolution unknown.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
O que está faltando? Seria o hibernate.c3p0.maxIdleTime ?