一.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>

使用schemaExport自动生成表结构的更多相关文章

  1. hibernate.hbm2ddl.auto=update不能自动生成表结构

    在写上篇文章<spring整合springmvc和hibernate>的时候,曾遇到一个问题 INFO: Server startup in 8102 ms Hibernate: inse ...

  2. 利用powerDesigner15.1连接oracle数据库并自动生成表结构

    利用powerDesigner15.1连接oracle数据库并自动生成表结构 参考:http://blog.csdn.net/qq_24531461/article/details/76713802 ...

  3. Hibernate之SchemaExport+配置文件生成表结构

    首先要生成表,得先有实体类,以Person.java为例: /** * * @author Administrator * @hibernate.class table="T_Person& ...

  4. 菜鸟学SSH(十一)——Hibernate之SchemaExport+配置文件生成表结构

    今天说点基础的东西,说说怎样通过SchemaExport跟Hibernate的配置文件生成表结构.事实上方法很easy,仅仅须要两个配置文件,两个Java类就能够完毕. 首先要生成表,得先有实体类,以 ...

  5. Hibernate使用自定义脚本替换注解或者xml文件中的自动生成表结构

    本文作者:苏生米沿 本文地址:http://blog.csdn.net/sushengmiyan/article/details/50534361 我们都清楚,可以使用hibernate的metada ...

  6. Spring4整合Hibernate5时不能自动生成表结构

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: Spring4整合Hibernate5时,不再使用hibernate.cfg.xml,将其内容整合到Spring配置文件中,启动后不能 ...

  7. hibernate如何配置自动生成表

    hibernate自动生成表有两种方法: 1.直接写代码,通过方法来创建数据库表. 2.通过 hibernate.cfg.xml配置标签来创建数据表. 下面依次实现: 1.直接写代码,通过方法来创建数 ...

  8. 基于PHP和mysql的自动生成表单

    开发背景:公司要求管理系统能够由管理员在前台页面管理系统表单,能够对表单进行增删改查基本操作,表单的各个字段都可以被修改.删除,可以添加新的字段,并且不影响系统正常运行,前台表单展示要由系统自动处理, ...

  9. EF:根据实体类生成表结构SQL

    根据实体类生成表结构SQL: PM> Enable-Migrations -ProjectName Domain -StartUpProjectName Handler -Force PM> ...

随机推荐

  1. UE4 读取本地图片

    参考链接:https://answers.unrealengine.com/questions/235086/texture-2d-shows-wrong-colors-from-jpeg-on-ht ...

  2. 【一天一道Leetcode】#190.Reverse Bits

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...

  3. FFmpeg源代码简单分析:av_find_decoder()和av_find_encoder()

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  4. ceil和floor函数的编程实践

    ceil()向上取整 floor向下取整 题目 在最近几场魔兽争霸赛中,赫柏对自己的表现都不满意. 为了尽快提升战力,赫柏来到了雷鸣交易行并找到了幻兽师格丽,打算让格丽为自己的七阶幻兽升星. 经过漫长 ...

  5. 刀片服务器和磁盘阵列卡(RAID)技术---永和维护

    近期客户需要更换服务器,客户把买好的服务器送来了,原本感觉很小的一个服务器,可当我看到的时候是一个大个的又长又宽,类似机房服务器的那种,后来米老师给大致讲解一番:这个是刀片服务器. 刀片服务器是指在标 ...

  6. 今日成为CSDN认证专家

    认证时写的申请材料: 程序猿一枚毕业于南开工作于上海.喜欢读书,喜欢跑步,激情似火,心静如水. 喜欢编程,喜欢寻根问底各种技术,喜欢在各种新技术中汲取营养. 喜欢分享,因此以一些高质量的博文来回报各位 ...

  7. Mybatis接口编程原理分析(三)

    前面两篇博客Mybatis接口编程原理分析(一)和Mybatis接口编程原理分析(二)我们介绍了MapperProxyFactory.MapperProxy和MapperMethod的操作及源码分析, ...

  8. Linux进程实践(2) --僵尸进程与文件共享

    孤儿进程与僵尸进程 孤儿进程: 如果父进程先退出,子进程还没退出那么子进程的父进程将变为init进程.(注:任何一个进程都必须有父进程) //生成孤儿进程 int main(int argc, cha ...

  9. 让你的动画不再生硬 Android插值器Interpolator使用秘籍

    有木有厌烦生硬的动画效果,想不想让你的动画变得圆滑且 欢迎收看本期的走进科学... 停,停,别打了,(.﹏.*) 我错了-- 我们要达到的效果: 先来回顾一下普通动画的用法吧. * 缩放动画 Scal ...

  10. 【网站搭建】搭建独立域名博客 -- 独立域名博客上线了 www.hanshuliang.com

    博客是安装在阿里云的服务器上. 小结 : -- 进入数据库命令 :mysql -uroot -p123456 ; -- 检查nginx配置语法 :.../nginx/sbin/nginx -t; -- ...