hibernate.hbm2dll.auto的設定介紹

來源:互聯網
上載者:User

標籤:http   io   ar   os   sp   for   on   資料   div   

 

  1. <?xml version=‘1.0‘ encoding=‘UTF-8‘?>  
  2. <!DOCTYPE hibernate-configuration PUBLIC  
  3.           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
  4.           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  
  5.   
  6. <!-- Generated by MyEclipse Hibernate Tools.                   -->  
  7. <hibernate-configuration>  
  8.   
  9. <session-factory>  
  10.     <property name="connection.username">root</property>  
  11.     <property name="connection.url">  
  12.         jdbc:mysql://localhost:3306/myhibernate  
  13.     </property>  
  14.     <property name="dialect">  
  15.         org.hibernate.dialect.MySQLDialect  
  16.     </property>  
  17.     <property name="connection.driver_class">  
  18.         com.mysql.jdbc.Driver  
  19.     </property>  
  20.      <property name="hbm2ddl.auto">create</property>  
  21.   
  22.     <property name="c3p0.min_size">5</property>  
  23.     <property name="c3p0.max_size">20</property>  
  24.     <property name="c3p0.timeout">300</property>  
  25.     <property name="c3p0.max_statements">50</property>  
  26.     <property name="c3p0.idle_test_period">3000</property>  
  27.     <property name="show_sql">true</property>  
  28.     <property name="format_sql">true</property>  
  29.     <property name="myeclipse.connection.profile">mysql</property>  
  30.     <property name="connection.password"></property>  
  31.       
  32.     <mapping resource="hello/Message.hbm.xml" />  
  33.   
  34. </session-factory>  
  35.   
  36. </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的設定介紹

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.