使用schemaExport自动生成表结构
来源:互联网 发布:淘宝买家留言怎么修改 编辑:程序博客网 时间:2024/04/30 15:55
一.Hibernate原生状态
1
2
3
4
5
Configuration cfg =
new
Configuration().configure();
SchemaExport export =
new
SchemaExport(cfg);
export.create(
true
,
true
);
二.Hibernate整合Spring
1.使用hibernate.cfg.xml原生配置
hibernate.cfg.xml同原生一样编写
在Spring主配置文件applicationContext中,引入hibernate.cfg.xml
使用SchemaExport生成数据库表的代码同上一致。
1
2
3
4
5
6
7
8
9
10
11
12
13
Spring applicationContext.xml
<
bean
id
=
"sessionFactory"
class
=
"org.springframework.orm.hibernate3.LocalSessionFactoryBean"
>
<
property
name
=
"configLocation"
value
=
"file:src/hibernate.cfg.xml"
>
</
property
>
</
bean
>
2.不使用hibernate.cfg.xml,在Spring的主配置文件applicationContext.xml中配置
完全不编写hibernate.cfg.xml,全部都在applicationContext.xml中配置
1
2
3
4
5
6
7
8
9
10
11
12
13
ClassPathResource ac =
new
ClassPathResource(
"applicationContext.xml"
);
XmlBeanFactory xbf =
new
XmlBeanFactory(ac);
//注意: &sessionFactory ,一定要包含 & ,不加Spring返回的是Hibernate下的SessionFactoryImpl类
LocalSessionFactoryBean lsfb=(LocalSessionFactoryBean) xbf.getBean(
"&sessionFactory"
);
Configuration cfg=lsfb.getConfiguration();
SchemaExport export=
new
SchemaExport(cfg);
export.create(
true
,
false
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!-- 配置数据源-->
<
bean
id
=
"dataSource"
class
=
"org.springframework.jdbc.datasource.DriverManagerDataSource"
>
<
property
name
=
"driverClassName"
value
=
"${jdbc.driverClassName}"
/>
<
property
name
=
"url"
value
=
"${jdbc.url}"
/>
<
property
name
=
"username"
value
=
"${jdbc.username}"
/>
<
property
name
=
"password"
value
=
"${jdbc.password}"
/>
</
bean
>
<!-- 配置sessionfactory,该配置替代了hibernate.cfg.xml的配置 -->
<
bean
id
=
"sessionFactory"
class
=
"org.springframework.orm.hibernate3.LocalSessionFactoryBean"
>
<
property
name
=
"dataSource"
ref
=
"dataSource"
></
property
>
<
property
name
=
"mappingResources"
>
<
list
>
<
value
>xxx/xxx/model/User.hbm.xml</
value
>
</
list
>
</
property
>
<
property
name
=
"hibernateProperties"
>
<
props
>
<
prop
key
=
"hibernate.dialect"
>org.hibernate.dialect.MySQLDialect</
prop
>
<
prop
key
=
"hibernate.show_sql"
>true</
prop
>
<
prop
key
=
"hibernate.format_sql"
>true</
prop
>
</
props
>
</
property
>
</
bean
>
0 0
- 使用schemaExport自动生成表结构
- Hibernate 使用SchemaExport自动生成表
- Hibernate使用SchemaExport和AnnotationConfiguration生成表结构
- 使用 SchemaExport 自动建表
- 使用 SchemaExport 自动建表
- 使用 SchemaExport 自动建表
- hibernate使用SchemaExport自动生成数据表
- SchemaExport 类使用(自动生成数据表)
- 使用SchemaExport生成数据库表
- Hibernate之SchemaExport+配置文件生成表结构
- 使用SchemaExport生成数据表
- 【SSH】-Hibernate之SchemaExport+配置文件生成表结构
- 【Hibernate】——SchemaExport自动生成数据库表
- Hibernate整合Spring后,如何使用SchemaExport生成数据库表
- hibernate使用SchemaExport生成对应的数据库表
- Hibernate 基于注解的SessionFactory类的生成以及自动生成表SchemaExport类的
- Hibernate5.x 使用SchemaExport生成数据表
- 菜鸟学SSH(十一)——Hibernate之SchemaExport+配置文件生成表结构
- iOS 集合的深复制与浅复制
- Context分析
- 安全思维导图
- 《Effective java》读书记录-第4条-通过私有构造器强化不可实例化的能力
- 项目在使用easyui时遇到的问题
- 使用schemaExport自动生成表结构
- Linux为什么最多能分4个四个主分区的解释(windows也一样吧)
- TabHost的两种用法-Android学习笔记
- 第六届福建省大学生程序设计竞赛——G Simple String Problem(状态压缩dp)
- WebView的使用
- Spring整合mybatis
- Elasticsearch学习笔记(一)简介
- Apache Thrift - 可伸缩的跨语言服务开发框架
- Unreal Engine 4 Console Variables and Commands