电光石火-穿越时空电光石火-穿越时空


hibernate自动建表

表结构和数据总是在程序执行的时候无端的修改,折腾了好长时间,查了很长时间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自动更新数据库结构

如果发现数据库表丢失或新增,请检查hibernate.hbm2ddl.auto的配置 可设置 <property name="hibernate.hbm2ddl.auto" value="none" />

本博客所有文章如无特别注明均为原创。作者:似水的流年
版权所有:《电光石火-穿越时空》 => hibernate自动建表
本文地址:http://www.ilkhome.cn/index.php/archives/487/
欢迎转载!复制或转载请以超链接形式注明,文章为 似水的流年 原创,并注明原文地址 hibernate自动建表,谢谢。

评论