標籤:hibernate 自動建表
1、資料庫方言配置,根據不同資料庫版本,以及使用的資料庫,選擇合適的方言
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
2、設定檔中使用了create-drop屬性,資料庫表其實已經建立,只是又被刪除了:
<property name="hbm2ddl.auto">create-drop</property> 只要把create-drop替換為create或update即可
3、預設的資料庫類型錯誤。
把mysql中my.ini檔案中配置的 MyISAM 變成 INNODB,代碼如下:
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
4、如果在spring裡面整合hibernate3,設定檔中每行的末尾一定不能有空格
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect//注意這些地方沒有空格
hibernate.hbm2ddl.auto=update//注意這些地方沒有空格
hibernate.show_sql=false//注意這些地方沒有空格
hibernate.format_sql=false//注意這些地方沒有空格
</value>
</property>
5、hbm實體類設定檔中定義的元素含有sql的關鍵字
例如: <property name="name"></property>
<property name="birthday"></property>
<property name="from"></property> 代碼中含有"from"關鍵字.
Hibernate自動建表失敗原因總結