创建 MySqlInnoDBDialect 如下
public class MySqlInnoDBDialect extends MySQL5Dialect
{
public boolean supportsCascadeDelete()
{
return true;
}
public String getTableTypeString()
{
return " ENGINE=InnoDB DEFAULT CHARSET=utf8";
}
public boolean hasSelfReferentialForeignKeyBug()
{
return true;
}
}
在hibernate.cfg.xml配置修改
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
</property>
这样创建的表格编码就是 InnoDB UTF8
已经创建的表格 只能用sql 语句自行修改了
本文介绍如何通过自定义Hibernate方言设置MySQL使用InnoDB存储引擎并指定字符集为utf8。此外,还提供了配置hibernate.cfg.xml文件的具体示例。

2363

被折叠的 条评论
为什么被折叠?



