今天遇到一个有意思的问题,我目前做的一个网站采用Spring MVC + Spring + Hibernate的架构,我通过页面插入了一些数据到数据库,可是每次重启tomcat之后,数据都莫名其妙地丢失了,但是我确定数据库中原本是有数据的,数据一定是在应用服务器重启之后被清除的,百思不得其解,忽然想到有可能是昨天修改了Hibernate配置文件导致的。

我的Hibernate配置文件:

<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
</session-factory>
</hibernate-configuration>

问题就出在我把hbm2ddl.auto的值设为create了,根据Hibernate的文档,hbm2ddl.auto有四个可选值:

定义
update 最常用的值,第一次加载hibernate时根据model类会自动建立起表的结构(前提是先建立好数据库),以后加载hibernate时根据 model类自动更新表结构,即使表结构改变了但表中的行仍然存在不会删除以前的行。要注意的是当部署到服务器后,表结构是不会被马上建立起来的,是要等 应用第一次运行起来后才会
validate 每次加载hibernate时,验证创建数据库表结构,只会和数据库中的表进行比较,不会创建新表,但是会插入新值
create 每次加载hibernate时都会删除上一次的生成的表,然后根据你的model类再重新来生成新表,哪怕两次没有任何改变也要这样执行
create-drop 每次加载hibernate时根据model类生成表,但是sessionFactory一关闭,表就自动删除

如果你不确定如何设置这个值的话,就设置为“none”吧。

Hibernate配置文件的hbm2ddl.auto属性的更多相关文章

  1. [原创]java WEB学习笔记80:Hibernate学习之路--- hibernate配置文件:JDBC 连接属性,C3P0 数据库连接池属性等

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  2. (转)hibernate 之hiberante.hbm2ddl.auto 参数的配置

    我们在搭建环境的时候,在配置文件中有一个属性标签为: 完整配置如下 <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernat ...

  3. hibernate配置文件中的catalog属性

    在hibernate表的映射文件中 <hibernate-mapping>    <class name="com.sooyie.hibernate.orm.Link&qu ...

  4. hibernate篇章四-- Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置

    我们在搭建环境的时候,在配置文件中有一个属性标签为: <property name="hibernate.hbm2ddl.auto">     </propert ...

  5. Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置

    我们在搭建环境的时候,在配置文件中有一个属性标签为: <property name="hibernate.hbm2ddl.auto">     </propert ...

  6. hibernate.hbm2ddl.auto配置详解

    hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下:<properties><property name="hibernate. ...

  7. Mingyang.net:hibernate.hbm2ddl.auto配置详解【转】

    原文地址:http://www.cnblogs.com/feilong3540717/archive/2011/12/19/2293038.html hibernate.cfg.xml 中hibern ...

  8. Hibernate hbm2ddl.auto DDL语句 控制台输出的配置

    在开发中我们需要知道hbm2ddl.auto生成的SQL语句,来判断代码的正确性,现在记录配置的过程. Hibernate的DDL语句在控制台的输出配置: 一.在lib中确保只有下面的三个相关包:1) ...

  9. <property name="hibernate.hbm2ddl.auto">update</property> 问题

    其实这个hibernate.hbm2ddl.auto参数的作用主要用于:自动创建|更新|验证数据库表结构.如果不是此方面的需求建议set value="none".create:每 ...

随机推荐

  1. HTML5学习总结——本地存储

    一.HTML4客户端存储 B/S架构的应用大量的信息存储在服务器端,客户端通过请求响应的方式从服务器获得数据,这样集中存储也会给服务器带来相应的压力,有些数据可以直接存储在客户端,传统的Web技术中会 ...

  2. spark yarn任务的executor 无故 timeout之原因分析

    问题: 用  spark-submit --master yarn --deploy-mode cluster --driver-memory 2G --num-executors 6 --execu ...

  3. MyBatis-Generator 逆向工程(生成异常缺少部分的方法)

    今日在使用 MyBatis-Generator 逆向工程时遇到了生成 mapper.java  , mapper.xml  时缺少部分方法. 正常的 Mapper.java 示例: public in ...

  4. Mac OS启动服务优化高级篇(launchd tuning)

    Mac下的启动服务主要有三个地方可配置:1,系统偏好设置->帐户->登陆项2,/System/Library/StartupItems 和 /Library/StartupItems/3, ...

  5. github本地库及clone常用命令

    新建本地库 1. cd d: 2. mkdir git 3. cd git 4. git init 5. git remote add  origin git@github.com:swportal/ ...

  6. bison实例

    逆波兰记号计算器[文件名rpcalc.y]%{ #define YYSTYPE double #include <stdio.h> #include <math.h> #inc ...

  7. 用Karma和Jasmine测试Angular应用

    TEST: Before you've written any of the code, you know how you want it to behave. You have a specific ...

  8. asp xml对象转换为string

    'xml文件中没有属性的情况 Dim xmlStrxmlStr="<root><count>1</count><error>0</err ...

  9. sql 各种格式

    --以2013-12-10 12:56:55为例--convert(nvarchar(10),CreateDate,120)      =>      2013-12-10--DATEPART( ...

  10. python修炼4

    ---恢复内容开始--- 集合 建立  set() ={},集合没有顺序,由不可改变的数字 ,字符串,元组构成 #交集print(a&b) #a.intersection(b) #并集prin ...