標籤:http io ar os sp for on 資料 div
- <?xml version=‘1.0‘ encoding=‘UTF-8‘?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
-
- <!-- Generated by MyEclipse Hibernate Tools. -->
- <hibernate-configuration>
-
- <session-factory>
- <property name="connection.username">root</property>
- <property name="connection.url">
- jdbc:mysql://localhost:3306/myhibernate
- </property>
- <property name="dialect">
- org.hibernate.dialect.MySQLDialect
- </property>
- <property name="connection.driver_class">
- com.mysql.jdbc.Driver
- </property>
- <property name="hbm2ddl.auto">create</property>
-
- <property name="c3p0.min_size">5</property>
- <property name="c3p0.max_size">20</property>
- <property name="c3p0.timeout">300</property>
- <property name="c3p0.max_statements">50</property>
- <property name="c3p0.idle_test_period">3000</property>
- <property name="show_sql">true</property>
- <property name="format_sql">true</property>
- <property name="myeclipse.connection.profile">mysql</property>
- <property name="connection.password"></property>
-
- <mapping resource="hello/Message.hbm.xml" />
-
- </session-factory>
-
- </hibernate-configuration>
validate 載入hibernate時,驗證建立資料庫表結構
create 每次載入hibernate,重新建立資料庫表結構,這就是導致資料庫表資料丟失的原因。
create-drop 載入hibernate時建立,退出是刪除表結構
update 載入hibernate自動更新資料庫結構
在本機開發調試初始化資料的時候可以選擇create、update等。
但是網站發布正式版本的時候,對資料庫現有的資料或表結構進行自動的更新是很危險的。此時此刻應該由DBA同志通過手工的方式進行背景資料庫操作。
hibernate.hbm2ddl.auto的值建議是“none”或“validate”。“validate”應該是最好的選擇:這樣 spring在載入之初,如果model層和資料庫表結構不同,就會報錯,這樣有助於技術營運預先發現問題。
hibernate.hbm2dll.auto的設定介紹