hibernate自动建表时设置编码格式

  hibernate 自动建表时在 hibernate 配置文件中加入

<!-- 设置编码格式 -->
<property name="hibernate.connection.useUnicode">true</property> 
<property name="hibernate.connection.characterEncoding">UTF-8</property>

  没有起作用。

  在url中加入?useUnicode=true&amp;characterEncoding=utf8

  并且重写 MySQL5InnoDBDialect,然后在配置文件中将方言指定成重写后的方言

package com.oy.utils;

import org.hibernate.dialect.MySQL5InnoDBDialect;

public class CustomerDialect extends MySQL5InnoDBDialect {
    public String getTableTypeString() {
        return " ENGINE=InnoDB DEFAULT CHARSET=utf8";
    }
}

  

  hibernate.cfg.xml 配置

<!-- 配置方言 -->
<property name="hibernate.dialect">com.oy.utils.CustomerDialect</property>

---

原文地址:https://www.cnblogs.com/xy-ouyang/p/13123511.html