问题
Our project uses Hibernate (3.3.2) with c3p0 as our connection pool. For a while, it seems there were some c3p0 properties in a c3p0.properties file, and others in hibernate.cfg.xml. I've just moved the last two c3p0 properties into hibernate.cfg.xml and confirmed they are being respected.
Is there ANY reason to keep around the c3p0 properties file, when c3p0 properties can be specified in hibernate.cfg.xml? Such as there being a property that can't be configured there, or another reason I'm not thinking of. It seems to me that specifying c3p0 properties in two places just causes confusion,
I think there was a previous belief that some properties couldn't be passed through in hibernate.cfg.xml, which I expect is just a myth. That is the primary reason for this question.
回答1:
No, no reason. (I don't even have hibernate.cfg.xml - everything is in the spring configuration)
回答2:
What you say doesn't seem to match with the c3p0 docs. Namely it seems there is only a subset of c3p0 parameters that can be accessed through hibernate.cfg.xml. Everything else must be set through a separate c3p0.properties file. See http://www.mchange.com/projects/c3p0/index.html#hibernate-specific
Edit: It seems the c3p0 docs are completely wrong. If you do as they say (e.g. include an additional c3p0.properties file) it will be ignored. However, if you simply add the properties to the hibernate config file in the same fashion, it works fine. E.g. adding the following to hibernate.cfg.xml worked, where the prescribed method did not:
<property name="hibernate.c3p0.acquireRetryAttempts">100</property>
<property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces">true</property>
<property name="hibernate.c3p0.unreturnedConnectionTimeout">120</property>
<property name="hibernate.c3p0.checkoutTimeout">30000</property>
There's 2 hours of my life i won't get back. :-(
来源:https://stackoverflow.com/questions/5081866/is-there-any-reason-to-keep-around-a-c3p0-properties-file-when-you-use-hibernate