<property name="hibernate.hbm2ddl.auto" value="update" />
Hibernate Reference Documentation解釋如下:
hibernate.hbm2ddl.auto Automatically validate or export schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly. eg. validate | update | create | create-drop
這個參數的作用主要用于:自動創建|更新|驗證數據庫表結構。
如果沒有此方面的需求建議不設置此屬性,默認是不對數據庫結構作任何改變
其它幾個參數的意思:
validate
每次加載hibernate時,驗證創建數據庫表結構,只會和數據庫中的表進行比較,不會創建新表,但是會插入新值。
create
每次加載hibernate時都會刪除上一次的生成的表,然后根據你的model類再重新來生成新表,哪怕兩次沒有任何改變也要這樣執行,這就是導致數據庫表數據丟失的一個重要原因。
create-drop
每次加載hibernate時根據model類生成表,但是sessionFactory一關閉,表就自動刪除。
update
最常用的屬性,第一次加載hibernate時根據model類會自動建立起表的結構(前提是先建立好數據庫),以后加載hibernate時根據 model類自動更新表結構,即使表結構改變了但表中的行仍然存在不會刪除以前的行。要注意的是當部署到服務器后,表結構是不會被馬上建立起來的,是要等 應用第一次運行起來后才會。
posted on 2011-04-17 16:53
donghang73 閱讀(559)
評論(0) 編輯 收藏 所屬分類:
學習筆記