MySQL UTF8 with Hibernate 3 and Spring
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?
Solved, it wasn't an Hibernate problem, Tomcat was not configured to encode incoming requests as UTF-8.
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.
精彩评论