Hibernate自动建表、更新表结构的配置方法

来源:互联网 发布:京瓷6525网络打印设置 编辑:程序博客网 时间:2024/05/22 03:35



Hibernate 自动建表 更新表结构,就在hibernate.cfg.xml中添加:

1.<property name="hibernate.hbm2ddl.auto">create</property> 加载hibernate.cfg.xml时,创建新表(如果原来存在,先删除)


2.<property name="hibernate.hbm2ddl.auto">update</property> 加载hibernate.cfg.xml时,更新表结构(如果原表不存在,就创建新表;如

果缺少相应的字段,就加入;对于原来存在的多余字段,不作处理)


3.<property name="hibernate.hbm2ddl.auto">create-drop</property> 加载hibernate时创建,退出时删除表结构


4.<property name="hibernate.hbm2ddl.auto">validate</property> 加载hibernate时,验证创建数据库表结构

0 0
原创粉丝点击