欢迎光临郝学武的blog。

hibernate的hibernate.hbm2ddl.auto属性

Posted on 2008-09-19 18:10 陕西BOY 阅读(8017) 评论(2)  编辑  收藏

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

Feedback

# re: hibernate的hibernate.hbm2ddl.auto属性[未登录]  回复  更多评论   

2008-09-20 11:02 by
你好 我是出版社的编辑,我看到你博客中的内容,感觉写的非常好,如果想把这些内容和更多的人分享,可以和我联系,把这些东西写成书。现在有一本Java数据库编程的书。
我的邮箱:books_522008@yahoo.com.cn

# re: hibernate的hibernate.hbm2ddl.auto属性[未登录]  回复  更多评论   

2014-05-04 16:43 by 啊啊
啊啊

只有注册用户登录后才能发表评论。


网站导航:
 

posts - 17, comments - 65, trackbacks - 0, articles - 28

Copyright © 陕西BOY