`
yzl495
  • 浏览: 48623 次
  • 性别: Icon_minigender_1
  • 来自: 赣州
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

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时,验证创建数据库表结构

5.在applicationContext.xml文件中添加 

   <property name="schemaUpdate">
   <value>true</value>
   </property>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics