Spring Mvc Hibernate Encoding/Multi-line import sql

前端 未结 1 710
情歌与酒
情歌与酒 2021-01-20 19:10

I am working on Spring MVC,

On project startup i have set database to import default sql with hibernate configuration hibernate.hbm2d

相关标签:
1条回答
  • 2021-01-20 19:14
    1. Make sure you are setting the JDBC driver to use UTF-8:

      jdbc:mysql://dbname?useUnicode=true&characterEncoding=utf-8

    2. 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
    
    0 讨论(0)
提交回复
热议问题