Posted on 2008-09-19 18:10
陜西BOY 閱讀(8034)
評論(2) 編輯 收藏
前天做項目的時候表結構和數據總是在程序執行的時候無端的修改,折騰了好長時間,查了很長時間hibernate的數據庫映射文件和接口程序,始終沒有發現有什么錯誤,到最后才發現了它!
<property name="hibernate.hbm2ddl.auto" value="update" />
解釋如下:
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
其實這個參數的作用主要用于:自動創建|更新|驗證數據庫表結構。
如果沒有此方面的需求建議set value="none".
其它幾個參數的意思:
validate 加載hibernate時,驗證創建數據庫表結構
create 每次加載hibernate,重新創建數據庫表結構
create-drop 加載hibernate時創建,退出是刪除表結構
update 加載hibernate自動更新數據庫結構