做hibernate项目,配置自动生成表失败
正确生成表代码如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 第一部分:配置数据库信息 必须 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///hibernate_day01</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<!-- 第二部分:配置hibernate信息 可选 -->
<!-- 输出底层sql语句 -->
<property name="hibernate.show_sql">true</property>
<!-- 输出底层sql语句格式 -->
<property name="hibernate.format_sql">true</property>
<!-- hibernate帮创建表,需要配置之后
update:如果已经有表,更新,如果没有,创建
-->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 配置数据库方言
让hibernate框架识别不同数据库自己持有的语句
-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- 第三部分:把映射文件放到核心配置文件中 必须 -->
<mapping resource="com/entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
其中配置数据库方言尝试过如下配置均失败:
1、教学视频中的方言配置代码:
<property name="hibernate.dialect">org.hibernate.dialect.MySQDialect</property>
2、查阅其他博客的方言配置代码:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
问题解决:
hibernate 配置自动生成表 失败的原因
Mysql 版本 5.0以前的Hibernate 方言是:
org.hibernate.dialect.MySQLDialect
Mysql 版本 5.0以后的Hibernate 方言是:
org.hibernate.dialect.MySQL5InnoDBDialect