Hibernate自動建表失敗原因總結

來源:互聯網
上載者:User

標籤: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自動建表失敗原因總結

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.