其实很简单

第一种方式使用hiberante.cfg.xml:

hiberante.cfg.xml配置如下:

<!DOCTYPE hibernate-configuration PUBLIC
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.hbm2ddl.auto">update</property>
  <property name="hibernate.dialect">
   org.hibernate.dialect.MySQLDialect
  </property>
  <property name="hibernate.show_sql">true</property>
  <mapping resource="com/oristand/hibernate/pojo/User.hbm.xml" />
 </session-factory>
</hibernate-configuration>
接着配置applicationContext-hibernate.xml

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
 <bean id="dataSource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName">
   <value>com.mysql.jdbc.Driver</value>
  </property>
  <property name="url">
   <value>jdbc:mysql://localhost:3306/ssh</value>
  </property>
  <property name="username">
   <value>root</value>
  </property>
  <property name="password">
   <value>123456</value>
  </property>
 </bean>

<bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref local="dataSource" />
  </property>
  <property name="configLocation">
       <value>classpath:hibernate.cfg.xml</value>
  </property>

</bean>
</beans>

第二种方式,不要hiberante.cft.xml,直接在applicationContext-hibernate.xml中配置:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
 <bean id="dataSource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName">
   <value>com.mysql.jdbc.Driver</value>
  </property>
  <property name="url">
   <value>jdbc:mysql://localhost:3306/ssh</value>
  </property>
  <property name="username">
   <value>root</value>
  </property>
  <property name="password">
   <value>123456</value>
  </property>
 </bean>

<bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref local="dataSource" />
  </property>
  <property name="mappingResources">
   <list>
    <!--
     !这里填写hibernate的映射文件路径
    -->
    <value>com/oristand/hibernate/pojo/User.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <!--
     配置Hibernate的方言
    -->
    <prop key="hibernate.dialect">
     org.hibernate.dialect.MySQLDialect
    </prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <!--
     输入由Hibernate生成的SQL语句,如果在hibernate.cfg.xml中也指定的话,会生成两条语句,在产品中最好关闭,即设为false
    -->
    <prop key="hibernate.show_sql">true</prop>
   </props>
  </property>
 </bean>
</beans>

spring管理hibernate的SessionFactory-多种配置方法相关推荐

  1. ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存

    ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate  : Hibernate是一个持久层框架,经常访问物理数据库 ...

  2. Spring管理Hibernate

    为什么要用Hibernate框架? 既然用Hibernate框架访问管理持久层,那为何又提到用Spring来管理以及整合Hibernate呢? 首先我们来看一下Hibernate进行操作的步骤.比如添 ...

  3. 如何修改ant-input的高度_如何利用好Solidworks零件及装配体的多种配置方法?

    首先,Solidworks提供了一个配置管理(ConfigurationManager)功能.该功能提供了在文件中生成.选择和查看零件及装配体的多种配置的方法.通俗点讲,就是能够分割并显示多个实例,同 ...

  4. Spring管理hibernate的事务的方法

    转自:http://yhjhappy234.blog.163.com/blog/static/31632832200952362948131/ 在某个方法前面添加事务标注 如,用银行存款进行买股票,则 ...

  5. Spring异常解决 java.lang.NullPointerException,配置spring管理hibernate时出错

    @Repository public class SysUerCDAO {@Autowiredprivate Hibernate_Credit hibernate_credit;/*** 根据手机号码 ...

  6. linux安全服务管理,Linux系统安全管理服务配置方法与技巧

    任何计算机安全措施的一个重要方面是维持实际控制服务的运行.本文向你展示了在Linux操作系统的PC机上如何配置安全服务管理. 任何计算机安全措施的一个重要方面是维持实际控制服务的运行,让不必要的网络服 ...

  7. 关于使用spring管理hibernate,能够管理事务,却不执行除查询外的增删改操作,不能让数据库数据改变的原因

    排除脏读的话 我终于学会了spring-aop管理事务,可以不写事务代码,详见我的博文 https://blog.csdn.net/thebestway/article/details/1012028 ...

  8. Spring+Hibernate+c3p0连接池配置-连接无法释放的问题解决方案

     1.Spring+Hibernate+c3p0连接池配置: <?xml version="1.0" encoding="UTF-8"?> < ...

  9. 为什么用Spring来管理Hibernate?

    为什么用Spring来管理Hibernate? 为什么要用Hibernate框架?这个在<Hibernate介绍>博客中已经提到了. 既然用Hibernate框架访问管理持久层,那为何又提 ...

最新文章

  1. 李开复对话彭特兰:AI不是单打独斗,应避免AI冷战
  2. eclipse mysql Xml配置_mysql8.0在eclipse中通过xml文件配置数据库连接池
  3. java 多线程 异步日志_精彩技巧(1)-- 异步打印日志的一点事
  4. 使用VMware进行基于Ubuntu16.04LTS的Spark集群搭建
  5. open函数和close函数的使用
  6. 第一次体验python有感
  7. 《pytorch》对CIFAR数据集的分类
  8. libpcre.so.1 cannot be found
  9. moment获取几小时前_请问怎么把“多少小时前”精确到“多少小时多少分钟前”...
  10. java CPU 占用过高
  11. 凤凰系统无法更新play服务器,凤凰OS:麦克风设置的问题
  12. 如何提高英文的科研写作能力——施一公
  13. Unix平台下的常用命令技巧之资源与性能
  14. 【删库跑路】使用Binlog日志恢复误删的MySQL数据
  15. 计算机网络配置ospf协议,OSPF路由协议配置(计算机网络实验)
  16. 原来,数据分析还可以这样干......
  17. Excel学习笔记:P33-来自2/8法则的神奇图表,让自己+公司的绩效事半功倍!
  18. Web前端:React Native Web与React — 比较指南
  19. 史上最全体检表、检验报告解析
  20. 中国大陆地区W酒店推出全新夏日计划“幻梦一夏”

热门文章

  1. CentOS系统如何搭建离线yum源
  2. 用markdown写博客园
  3. dirty_background_ration 与 /proc/sys/vm/dirty_ratio
  4. Win7无法远程桌面
  5. 2.对于所有对象都通用的方法_EJ
  6. WordCount单词计数
  7. JavaScript(循环)
  8. CCF-CSP 201712-2 游戏(C++实现)
  9. python 內建数据类型
  10. 四川阆中上演“万人同品腊八粥”