hibernate.hbm2dll.auto的设置介绍

  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层和数据库表结构不同,就会报错,这样有助于技术运维预先发现问题。

欧克蓝科技
原文地址:https://www.cnblogs.com/sias/p/4164207.html