hibernate.cfg.xml配置:<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration> <session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/ssh
</property>
<property name="connection.username">root</property>
<property name="connection.password">1111</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">ssh</property>
<property name="show_sql">true</property>
<mapping resource="com/csdn/ssh/entity/User.hbm.xml" />
<mapping resource="com/csdn/ssh/entity/Book.hbm.xml" /> </session-factory></hibernate-configuration>
applicationContext.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/tx 
   http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
http://www.springframework.org/schema/aop 
   http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <tx:advice id="txAdvice"
transaction-manager="myHibTransactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="do*" propagation="REQUIRED" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="bizMethods"
expression="execution(* com.csdn.ssh.biz.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
</aop:config> <bean id="baseDao" class="com.csdn.ssh.dao.impl.IBaseDaoImpl"></bean>
<bean id="baseBiz" class="com.csdn.ssh.biz.impl.IBaseBizImpl">
<property name="baseDao" ref="baseDao"></property>
</bean>
<bean id="BaseAction" class="com.csdn.ssh.action.BaseAction">
<property name="baseBiz" ref="baseBiz"></property>
</bean>

<bean id="userBiz" class="com.csdn.ssh.biz.impl.IUserBizImpl"></bean>
<bean id="userAction" class="com.csdn.ssh.action.UserAction">
<property name="userBiz" ref="userBiz"></property>
</bean></beans>
IBaseDaoImpl实现类:public class IBaseDaoImpl extends HibernateDaoSupport implements IBaseDao {
/**
 * 根据hql语句查询数据、返回ArrayList集合
 * @param hql
 * @return list
 */
public ArrayList find(String hql) {
// TODO Auto-generated method stub
ArrayList list = (ArrayList) super.getHibernateTemplate().find(hql);
return list;
}
实现类继承 HibernateDaoSupport ,请问:sessionFactory该如何配置?

解决方案 »

  1.   

    整合的时候它是在application.xml里面的
    整合的时候 hibernate.cfg.xml 会被合并到application.xml中
     <session-factory>
            <property name="dialect">
                org.hibernate.dialect.MySQLDialect
            </property>
            <property name="connection.url">
                jdbc:mysql://localhost:3306/ssh
            </property>
            <property name="connection.username">root</property>
            <property name="connection.password">1111</property>
            <property name="connection.driver_class">
                com.mysql.jdbc.Driver
            </property>
            <property name="myeclipse.connection.profile">ssh</property>
            <property name="show_sql">true</property>
            <mapping resource="com/csdn/ssh/entity/User.hbm.xml" />
            <mapping resource="com/csdn/ssh/entity/Book.hbm.xml" />    </session-factory>
      

  2.   

    具了解:合入Spring里面的是先引用Spring再引用Hibernate的;另一种方式先引用Hibernate再引用Spring的,就是我这样的。
      

  3.   

    [code=Java]
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="configLocation"
                value="file:src/hibernate.cfg.xml">
            </property>
        </bean>
        <bean id="UsertableDAO" class="spring_hibernate_dao.UsertableDAO">
            <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>
        </bean></beans>[code=Java]
      

  4.   

    包  Spring 2.0 与 Hibernate 3.0 冲突。会引发 实体类 不能创建 以及  sessionFactory 不能创建
      

  5.   

    这两个集成都是myeclipse自动的呀你有什么问题吗