hibernate 根据配置生成数据库
来源:互联网 发布:biorad cfx96 软件 编辑:程序博客网 时间:2024/05/22 15:15
spring + hibernate:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" p:dataSource-ref="dataSource"> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean>起作用的是<prop key="hibernate.hbm2ddl.auto">update</prop>这一句,自动建表
纯hibernate:
只要在hibernate.cfg.xml添加这句话,就可以自动生成数据表 <property name="hibernate.hbm2ddl.auto">update</property> update:表示自动根据model对象来更新表结构,启动hibernate时会自动检查数据库,如果缺少表,则自动建表;如果表里缺少列,则自动添加列。 还有其他的参数: create:启动hibernate时,自动删除原来的表,新建所有的表,所以每次启动后的以前数据都会丢失。 create-drop:启动hibernate时,自动创建表,程序关闭时,自动把相应的表都删除。所以程序结束时,表和数据也不会再存在。 PS:数据库要预先建立好,因为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" />
0 0
- hibernate 根据配置生成数据库
- hibernate 根据对象关系表生成 数据库
- hibernate根据配置文件生成数据库表
- Hibernate根据实体生成数据库表
- hibernate 根据配置文件自动生成数据库表
- hibernate根据映射文件生成数据库对象
- 根据Hibernate 实体类配置的xml 生成数据库表代码
- hibernate 自动生成数据库(根据hibernate配置文件)
- 根据hibernate配置文件生成数据库建表脚本
- 使用 hibernate 根据映射文件生成数据库表
- 根据Hibernate映射文件和实体类生成数据库
- 根据hibernate生成表
- 根据hibernate生成表
- 根据模型生成数据库
- 如何根据hibernate的实体类和实体类配置文件生成数据库的表
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 如何根据hibernate的实体类和实体类配置文件生成数据库的表
- hibernate tools 根据数据库中mysql表生成 .java .hbm.xml
- my97datepicker日期控件使用方法
- ios-loadView,viewDidLoad,viewDidUnload三者之间的关系
- windows批处理实现telnet登陆和运行命令--设置缺省输入法为英文
- 几张简约而不简单的JavaScript学习树状图
- AS3 Embed标签的数据类型
- hibernate 根据配置生成数据库
- 基于二维拓扑数的可达性查询
- 辛星笔记——VIM学习篇(推荐阅读)
- WebService: 测试窗体只能用于来自本地计算机的请求。
- 快速集成下拉上拉刷新demo
- Spring3.x--使用SpEL表达式装配
- c++虚函数表解析
- 简单移动动画
- Android中ListView分页加载数据