hbm2ddl

hbm2ddl:

Hibernate mapping to data defination language  hibernate 映射变为DDL(数据定义)语言

<property name="hbm2ddl.auto">update</property>

有四个值:

hibernate.hbm2ddl.auto Automatically validates or exports 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.

e.g. validate | update | create | create-drop

validate:每次都进行验证;

update:

  如果数据库不存在某个字段,那就添加该字段;

  如果model配置的字段长度发生改变,update不会修改表中的字段长度;

  如果 model 中不存在某个字段而对应的表中有,进行数据更新操作时也不会动表的数据结构;

  常用。

create:

  每次进行数据操作前先删除hibernate.cfg.xml配置所能读取的跟数据库中表名相同的所有表,再新建表,再插入数据。

  做简单实验可以用,对于数据多的测试环境或生产环境是肯定不会用的。

create-drop:

  每次 SessionFactory 已关闭,所有表就删掉,我就没弄懂,这玩意儿有啥用,基本不会用。

英文文档:

  hibernate:

  annotation:

  中文api链接: http://pan.baidu.com/s/1c14Zr4s 密码: tnrg

链接: http://pan.baidu.com/s/1hsP0fyO 密码: 6b8e

所需jar链接: http://pan.baidu.com/s/1i4M0bNB 密码: jfjk

原文地址:https://www.cnblogs.com/ShawnYang/p/6693867.html