MySQL UTF8 与 Hibernate 3 和 Spring
模式中的所有表都设置为 UTF-8 作为默认字符集,但我无法让 Hibernate 正确插入“é”或“ñ”等符号(它们插入为“Ë”或“±” ”)。
我的配置如下:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="${db.url}"></property>
<property name="username" value="${db.user}"></property>
<property name="password" value="${db.password}"></property>
<property name="driverClassName" value="${db.driver}"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
我尝试将 ?useUnicode=true&characterEncoding=UTF-8 添加到连接 URL,但没有结果...知道吗?
All my tables in the schema are set to UTF-8 as the default charset, but I can't manage to get Hibernate insert correctly symbols like "é" or "ñ" (they are inserted as "é" or "ñ").
My configuration is the following:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="${db.url}"></property>
<property name="username" value="${db.user}"></property>
<property name="password" value="${db.password}"></property>
<property name="driverClassName" value="${db.driver}"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
I've tried adding ?useUnicode=true&characterEncoding=UTF-8 to the connection URL, but with no results... Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已解决,这不是 Hibernate 问题,Tomcat 未配置为将传入请求编码为 UTF-8。
Solved, it wasn't an Hibernate problem, Tomcat was not configured to encode incoming requests as UTF-8.
添加休眠编码后它不起作用,但在页面级别添加编码后它起作用。
在jsp页面中添加编码后IT工作
我在jsp页面中添加了这个。
After adding hibernate encoding it did not work but it worked after adding encoding at page level.
IT worked after adding encoding in jsp page
I added this in jsp page.