I am working on Spring MVC,
On project startup i have set database
to import default sql
with hibernate configuration hibernate.hbm2d
Make sure you are setting the JDBC driver to use UTF-8:
jdbc:mysql://dbname?useUnicode=true&characterEncoding=utf-8
In persistence.xml
, set the hibernate connection charset:
<property name="hibernate.connection.charSet" value="UTF-8"/>
If your resources/import.sql
file is multi-line, add:
<property
name="hibernate.hbm2ddl.import_files_sql_extractor"
value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor"
/>
or for Spring Boot, in application.properties
:
spring.jpa.properties.hibernate.connection.charSet=UTF-8
spring.jpa.properties.hibernate.hbm2ddl.import_files_sql_extractor=org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor