spring会查找classpath中的文件名为hibernate.cfg.xml中配置文件,并根据它里面的一些参数实例化sessionFactory,这样hibernate就知道链接数据库的url、驱动程序名、用户名、密码、和一些映射信息等。

解决方案 »

  1.   

    上面是保留hibernate.cfg.xml的集成方式这个是不保留hiberante.cfg.xml的集成方式
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
    <props>
       <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
       <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>hl/ghost/frame/pojo/Users.hbm.xml</value>
    <value>hl/ghost/frame/pojo/Menu.hbm.xml</value>
    </list>
    </property>
    </bean>
      

  2.   

    实例化的sessionFactory是给谁用的??????
      

  3.   

    spring配置文件里说明sessionFactory给谁了对于不懂的框架,照做就是了,现在流行的是会用
      

  4.   

    spring里面注入到sessionFactory一般是服务于hibernate 的配置包括数据源、url,链接数据库信息等,还有一些hibernate的属性如:show_sql
      

  5.   

    spring会查找classpath中的文件名为hibernate.cfg.xml中配置文件,并根据它里面的一些参数实例化sessionFactory,这样hibernate就知道链接数据库的url、驱动程序名、用户名、密码、和一些映射信息等。答案就应该是这个实例化的sessionFactory哪里要用到你就通过配置文件注入进去就OK了!
    呵呵!
      

  6.   

    <!-- 配置sessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="configLocation">
                <value>classpath:hibernate.cfg.xml</value>
            </property>    
        </bean>spring整合hibernate和structs的方式类似(也只能是这样),就是spring“托管”(也就是负责创建及di依赖注入)hibernate或structs的“控制bean”
    对于structs就是action、对于hibernate就是sessionFactory。“托管”的方式就是将action、sessionFactory作为bean配置给spring这样。
    由于对于structs的action单件方式的大肆攻击、spring“托管”的action肯定是原型方式交付、而sessionFactory肯定是单件方式交付。
    sessionFactory相当于我们使用hibernate的“门面”,也就是“入口”,spring这样将门面一“托管”就相当于整合了hibernate
      

  7.   

    因为用到了spring,已将hibernate交给spring管理了,而Session又是从SessionFactory中拿到的,所以就要注入SessionFactory,又必须知道hibernate配置文件在哪里,对configLocation提供的是setter注入,所以就应该那样写,还有一种集成是将hibernate配置信息都写在了applicationContext.xml中,没用过,不是很清楚