如何用Spring,Hibernate 3.3和c3p0配置MySQL连接属性? [英] How to configure MySQL connection properties with Spring, Hibernate 3.3 and c3p0?

查看:235
本文介绍了如何用Spring,Hibernate 3.3和c3p0配置MySQL连接属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将应用程序从Hibernate 3.2升级到Hibernate 3.3。我虽然坚持使用默认连接池(Hibernate将其默认值从 Commons DBCP 更改为<因为我没有任何理由选择一个非默认的池。至少不是,但是之前使用过DBCP。



到目前为止,升级几乎没有任何问题。我唯一不能工作的就是将属性传递给底层的MySQL JDBC4Connection 。到目前为止,我使用DBCP的 BasicDataSource.addConnectionProperty(String,String)传递属性(useUnicode = true,characterEncodin = UTF-8,characterSetResults = UTF-8,zeroDateTimeBehavior = convertToNull)。

然而,除了将它们包含在JDBC URL中。 (这是我想避免的,因为我想保持URL的可配置性而不强迫用户包含这些参数。)



到目前为止,我尝试使用 ConnectionCustomizer 没有成功。其他建议吗?

解决方案

我再次回答自己的问题(另一位自学者?是的,请!): p>

com.mchange.v2.c3p0.ComboPooledDataSource 有一个属性属性。有趣的是,在用户和密码之后设置属性会覆盖它们。但是,在用户和密码按照预期工作之前设置属性。


I am currently in the process of upgrading an application from Hibernate 3.2 to Hibernate 3.3. I though I'd stick with the default connection pool (Hibernate changed its default from Commons DBCP to c3p0) as I don't have any good reason to choose a non-default pool. At least non but having used DBCP before.

The upgrade went pretty much without any problems so far. The only thing I can't get to work is passing properties to the underlying MySQL JDBC4Connection. Up to now, I used DBCP's BasicDataSource.addConnectionProperty(String,String) to pass properties (useUnicode=true, characterEncodin=UTF-8, characterSetResults=UTF-8, zeroDateTimeBehavior=convertToNull).

However, I can't find any way to do the same with c3p0 other than including them in the JDBC URL. (That's something I'd like to avoid as I wanna keep the URL configurable without forcing users to include those parameters.)

So far, I've tried to use a ConnectionCustomizer without success. Any other suggestions?

解决方案

Once again a question I answer myself (another self-learner? yes, please!):

com.mchange.v2.c3p0.ComboPooledDataSource has a property "properties". Interestingly, setting properties after user and password overrides them. But setting properties before user and password works as expected.

这篇关于如何用Spring,Hibernate 3.3和c3p0配置MySQL连接属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆