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"關鍵字.