日期:2014-05-20  浏览次数:20684 次

spring+hibernate整合配置问题
spring配置文件(application.xml)配置如下
Java code

        
             <!-- 配置sessionFactory -->
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      
        <property  name="configLocation">
           <value>classpath:hibernate.cfg.xml</value>
        </property>
      </bean>
      



hibernate.cfg.xml配置如下
Java code

<hibernate-configuration>

    <session-factory>

        <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
        <property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;databaseName=hibernateTest02</property>
        <property name="connection.username">sa</property>
        <property name="connection.password">123456</property>
        <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

        <property name="show_sql">true</property>

        <property name="hbm2ddl.auto">create</property>

        <mapping resource="com/chengge/bean/User.hbm.xml" />
        <mapping resource="com/chengge/bean/Class.hbm.xml" />

    </session-factory>

</hibernate-configuration>




但取出来的this.gethibernateTemplate()为空值(该测试类已经继承HibernateDaoSupport类)

为什么是空值。求解。。

------解决方案--------------------
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
这些是配置sqlserver的驱动名称的吗?查找准确点把。认真参照资料配置好配置文件。不行的话就去找个可运行的例子来参考参考。然后举一反三。祝好运。
------解决方案--------------------
参考下
<bean id="hibernateSession" 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
<property name="configLocation"> 
<value>file:src/horse.cfg.xml</value> 
</property> 
</bean>
------解决方案--------------------
dao类有没有注入sessionFacotory,spring的配置文件都贴出来看看
------解决方案--------------------
你的UserServiceImpl直接继承了HibernateDaoSupport么,如果是的话看配置我也没发现什么异常,帮不上啥忙了