我在保持模型對象的同時面臨UTF-8編碼問題。在土耳其'ı'是一封信。還有一些其他的土耳其字符包含在UTF-8編碼中。當我堅持我的模型對象時,所有'''字符被持續爲'?'到DB。我在Ubuntu Linux 64位操作系統上使用MySQL 5.5。此外,我已經將休眠& c3p0連接編碼屬性設置爲UTF-8。當我調試時,來自客戶端的數據是真實的。Hibernate在持久化對象時編碼錯誤[UTF-8]
這是我的配置,如果有人能幫助我,我會很開心。
在此先感謝。
春& Hibernate的配置
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="packagesToScan" value="com.tk.dms.model" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.useUnicode">true</prop>
<!-- c3p0 properties -->
<prop key="hibernate.c3p0.min_size">2</prop>
<prop key="hibernate.c3p0.max_size">50</prop>
<prop key="hibernate.c3p0.maxPoolSize">50</prop>
<prop key="hibernate.c3p0.minPoolSize">2</prop>
<prop key="hibernate.c3p0.initialPoolSize">2</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
</props>
</property>
</bean>
感謝很多pawelccb,加入charachter編碼到url解決了問題.. – talha06 2012-08-02 10:58:03
嘗試所有Hibernate和MySQL配置後,該過濾方法奏效。謝謝! – 2013-11-11 01:28:15
你救了我的一天......像魅力一樣工作...... – Babu 2015-01-09 16:04:05