Chinaunix首页 | 论坛 | 博客
  • 博客访问: 925079
  • 博文数量: 264
  • 博客积分: 10107
  • 博客等级: 上将
  • 技术积分: 2455
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-09 16:34
文章分类

全部博文(264)

文章存档

2012年(1)

2011年(11)

2010年(128)

2009年(82)

2008年(42)

我的朋友

分类: 系统运维

2010-12-24 14:07:07

前一段时间写过一篇:
struts+hibernate+spring详细示例——东方标准(专注IT、服务中国)
在那篇文章中,我是将Hibernate的SessionFactory单独写了一个工具类HibernateUtil……
今天我们把Spring的SessionFactory交给Spring的IoC容器来管理……
其实很简单
第一种方式:
hiberante.cfg.xml配置如下:
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 "">

 
  update
 
   org.hibernate.dialect.MySQLDialect
 

  true
 
 


接着配置applicationContext-hibernate.xml
 xmlns:xsi=""
 xmlns:aop=""
 xmlns:tx=""
 xsi:schemaLocation="
          
           ">
   class="org.springframework.jdbc.datasource.DriverManagerDataSource">
 
   com.mysql.jdbc.Driver
 

 
   jdbc:mysql://localhost:3306/ssh
 

 
   root
 

 
   123456
 

 
   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 
  
 

 
       classpath:hibernate.cfg.xml
 
 
第二种方式,不要hiberante.cft.xml,直接在applicationContext-hibernate.xml中配置:
 xmlns:xsi=""
 xmlns:aop=""
 xmlns:tx=""
 xsi:schemaLocation="
          
           ">
   class="org.springframework.jdbc.datasource.DriverManagerDataSource">
 
   com.mysql.jdbc.Driver
 

 
   jdbc:mysql://localhost:3306/ssh
 

 
   root
 

 
   123456
 

 
   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 
  
 

 
  
   
    com/oristand/hibernate/pojo/User.hbm.xml
  

 

 
  
   
   
     org.hibernate.dialect.MySQLDialect
   

    update
   
    true
  

 

 

 
 
阅读(1198) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~