Search code examples
javahibernatec3p0java.util.logging

How to I enable c3p0 logging within my hibernate class


I am using Java 8, Hibernate 4.3.11 and c3p0 9.2.1.

I define all my c3p0 properties from within my hibernate config class

e.g

  Configuration config = new org.hibernate.cfg.Configuration();
  config.setProperty("hibernate.c3p0.maxStatementsPerConnection","50");

this works great because it means everything works the same on different platforms (Mac, Windows, Linux, Docker etc)

But I could not get any c3p0 debugging output, I had some success by adding

-Dcom.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog

but using

config.setProperty("hibernate.c3p0.com.mchange.v2.log.MLog","com.mchange.v2.log.jdk14logging.Jdk14MLog");

instead has no effect.

Is it possible because adding as a system properties would require modification to build scripts for all platforms (we provided proper installers not just a jar file).


Solution

  • Try calling com.mchange.v2.log.MLog.refreshConfig(null, null) after you set the config property.

    One issue with setting on the command line vs. setting at run time is that class loading often triggers the read of the property. Which means that at run time the value is read before it is set by your code.