当您使用 hibernate.cfg.xml 时,是否有任何理由保留 c3p0.properties 文件?

发布于 2024-10-18 20:06:40 字数 359 浏览 6 评论 0原文

我们的项目使用 Hibernate (3.3.2) 和 c3p0 作为我们的连接池。有一段时间,c3p0.properties 文件中似乎有一些 c3p0 属性,而 hibernate.cfg.xml 中则有其他属性。我刚刚将最后两个 c3p0 属性移至 hibernate.cfg.xml 中并确认它们受到尊重。

当可以在 hibernate.cfg.xml 中指定 c3p0 属性时,是否有任何理由保留 c3p0 属性文件?比如有一个属性无法在那里配置,或者我没有想到的其他原因。在我看来,在两个地方指定 c3p0 属性只会引起混乱,

我认为以前有一种观点认为某些属性无法在 hibernate.cfg.xml 中传递,我认为这只是一个神话。这就是这个问题的主要原因。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风尘浪孓 2024-10-25 20:06:40

你说的似乎与c3p0文档不符。也就是说,似乎只有 c3p0 参数的子集可以通过 hibernate.cfg.xml 访问。其他所有内容都必须通过单独的 c3p0.properties 文件设置。
请参阅http://www.mchange.com/projects/c3p0/index。 html#hibernate-specific

编辑:c3p0 文档似乎完全错误。如果您按照他们所说的操作(例如包含附加的 c3p0.properties 文件),它将被忽略。但是,如果您只是以相同的方式将属性添加到 hibernate 配置文件中,它就可以正常工作。例如,将以下内容添加到 hibernate.cfg.xml 有效,而规定的方法无效:

<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>

我生命中的 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. :-(

落花浅忆 2024-10-25 20:06:40

不,没有理由。 (我什至没有 hibernate.cfg.xml - 一切都在 spring 配置中)

No, no reason. (I don't even have hibernate.cfg.xml - everything is in the spring configuration)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文