Hibernate mysql čć

穿精又带淫゛_ 提交于 2020-01-03 05:14:29

问题


Im having problem when i try to save Patient with familyname = 'Lučić' in MYSQL database using hibernate + jpa.

When i do regular INSERT INTO, letter č and ć are displayed correctly in database and on my jsf form, so im sure that charset on my form is correct and in database.

Here is my hibernate configuration:

app_persistance.dialect=org.hibernate.dialect.MySQLDialect
app_persistance.show_sql=true
app_persistance.generateDdl=true
app_persistance.minPoolSize=1
app_persistance.maxPoolSize=10
app_persistance.connection.url=jdbc:mysql://localhost:3306/dentapp
app_persistance.connection.username=root
app_persistance.connection.password=root
app_persistance.connection.driver_class=com.mysql.jdbc.Driver
app_persistance.hibernate.connection.CharSet=utf8_croatian_ci
app_persistance.hibernate.connection.characterEncoding=UTF-8
app_persistance.hibernate.connection.useUnicode=true
app_persistance.hbm2ddl=update

I tryed to debug and check if value familyname in Patient object from jsf form has right values ( č, ć ) in serviceImpl:

@Override
@Transactional
public Patient save(Patient patient) {
    return patientDAO.save(patient);
}

but everything seems to be fine in patient object so it has to be some problem with hibernate configuration. When hibernate+jpa is saving patient to db, it converts č,ć to ?? characters.

Can anyone point me to something, where i should look/read/check ?

Thanks !


回答1:


It seems that your connection is not using UTF8

Change

app_persistance.connection.url=jdbc:mysql://localhost:3306/dentapp

to

app_persistance.connection.url=jdbc:mysql://localhost:3306/dentapp?useUnicode=true&characterEncoding=utf-8


来源:https://stackoverflow.com/questions/19811687/hibernate-mysql-%c4%8d%c4%87

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!