JPA utf-8 characters not persisted

后端 未结 4 1146
我在风中等你
我在风中等你 2020-12-02 20:58

I have a simple web application where I use JPA.

I have an entity called BlogEntry.

When I submit a new BlogEntry, when I debug my applica

相关标签:
4条回答
  • 2020-12-02 21:27

    This solved it nicely:

    <property name="hibernate.connection.useUnicode" value="true" />
    <property name="hibernate.connection.characterEncoding" value="UTF-8" />
    

    Edit: with hibernate 4.3.1 this works:

    <property name="connection.useUnicode">true</property>
    <property name="connection.characterEncoding">utf-8</property>
    
    0 讨论(0)
  • 2020-12-02 21:33

    This helped in Spring Boot:

    spring.datasource.url=jdbc:mysql://localhost:3306/securitydb?useUnicode=yes&characterEncoding=UTF-8
    
    0 讨论(0)
  • 2020-12-02 21:39

    Another common mistake can be the wrong encoding of the database. If you just cerated the database without the correct encoding this error can also be a result. use

    create database mydb character set utf8 collate utf8_general_ci;
    

    instead of

    create database mydb;
    
    0 讨论(0)
  • 2020-12-02 21:50

    use the character encoding in the property of persistence.xml file

    <property name="javax.persistence.jdbc.url" 
       value="jdbc:mysql://localhost:3306/blogdatabase?useUnicode=yes&amp;characterEncoding=UTF-8"/>
    
    0 讨论(0)
提交回复
热议问题