为什么要同时使用bean id="transactionManager"和bean id="hibernateTemplate"呢?<?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:context="http://www.springframework.org/schema/context" 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.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">     <!-- 使用注解的方式,进行依赖注入 -->
<context:annotation-config /> <!-- 使用自动扫描机制,把@Component、@Service、@Controller、@Repository注解类,这些类纳入进spring容器中管理 -->
<context:component-scan base-package="cn.itcast" /> <!-- SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 使用Hibernate的配置文件中的配置 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- <property name="dataSource" ref="dataSource" /> -->
</bean> <!-- 事务 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <!-- 注解方式来打开事务, transaction-manager 为 transactionManager 时可以省略-->
<tx:annotation-driven transaction-manager="transactionManager" /> <!-- HibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

</beans>

解决方案 »

  1.   

    <!-- HibernateTemplate -->
        <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
            <property name="sessionFactory" ref="sessionFactory"></property>
        </bean>
    是定义了一个hibernateTemplate实例
      

  2.   

    transactionManager和hibernateTemplate
    有什么区别呢?
      

  3.   

    transactionManager是用来事务管理, 自动打开关闭事务
    hibernateTemplate用来简化session的操作
      

  4.   

    transactionManager是用来事务管理, 自动打开关闭事务,做了添删改但是数据库里没有反映。
    hibernateTemplate..整合框架时提供那些增删改查的模板。。
      

  5.   

    transactionManager 用来配置管理事务的, 
    hibernateTemplate 是一个模版,如果你继承的是HibernateDaoSupport的话,就需要hibernateTemplate来获得数据库联接,否则没有连接到数据库,怎么操作数据库?
      

  6.   

    比如你一个分页就要用hibernateTemplate
      

  7.   

    hibernateTemplate注入你的类之后,可以使用hibernateTemplate里面的getSession方法获得session,也可以直接调用封装了session.save()的save方法.用他可以对数据库操作而transactionManager是对事物的管理,打开和关闭事物
      

  8.   

    LZ,赶紧找本好书看一看吧,那是基础的东西~~~~,transactionManager 是你的事务,hibernateTemplate 是你的hibernate 配置
      

  9.   

    strut2.1.8+spring2.5(或3.0)+hibernate3.3结合,transactionManager是可以不再applicationContext.xml中配置的,为什么呀?
    如果想自己在service层管理事物改怎么做呀?
    你的业务类直接继承HibernateDaoTemplate就可以了,为什么要在xml中配置?
    希望高手指点一下,thanks!