只有手动进行事务管理才有数据进入, 我觉得可能代码上没有问题吧,
一开始以为是 事务没有配置好  但是查看了几遍, 也没看到什么错。我是这样想的
用一个BaseDAO 作为父类 其他DAO均extends这个父类 
该父类有sessionFactory属性 并有相应的get set方法
那么BaseDAO 的子类应该也有sessionFactory对象了吧我这里贴出了配置文件 和 2个 BaseDAO 和StuDAOImpl是在不知道哪里会错啊首先是application.xml ===========================================================<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
<tx:method name="show*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="exp1" expression="execution(* dao.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="exp1" />
</aop:config>
<!--事务管理配置结束 -->
<bean id="baseDAO" class="dao.BaseDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="userDAO" class="dao.impl.TbUserDAOImpl">
</bean> <!-- stu -->
<bean id="stuDAO" class="dao.impl.TbStuDAOImpl">
</bean>
<bean id="stuAction" class="action.StuAction">
<property name="stuDAO" ref="stuDAO" />
</bean> <!--  tea -->
<bean id="teaDAO" class="dao.impl.TbTeaDAOImpl">
</bean>
<bean id="teaAction" class="action.TeaAction"> </bean>
<!--  admin -->
<bean id="AdminAction" class="action.AdminAction">
<property name="stuDAO" ref="stuDAO" />
</bean>
</beans>
baseDAO==================================public class BaseDAO{
    private SessionFactory sessionFactory;
    
    public SessionFactory getSessionFactory() {
       return sessionFactory;
    }
 
    public void setSessionFactory(SessionFactory sessionFactory) {
       this.sessionFactory = sessionFactory;
    }

public Session getSession() {
return HibernateSessionFactory.getSession();
}

}stuDAOImpl==========================================================public class TbStuDAOImpl extends BaseDAO implements TbStuDAO { public void save(TbStu transientInstance) {
getSession().save(transientInstance);
}
....
}

解决方案 »

  1.   

    少一个什么属性啊? 是配置文件中有什么没有配吗?话说 expression="execution(* dao.impl.*.*(..))"  不应该是对dao.impl包中的类中的
    <tx:method name="save*" 。。 这些方法进行事务管理吗?今天郁闷了一天了啊
      

  2.   

    数据访问类要继承org.springframework.orm.hibernate3.support.HibernateDaoSupport
      

  3.   

    xmlns:tx="http://www.springframework.org/schema/tx"
      

  4.   

    我的dao都是自己写的, 不是自动生成 , 继承这个之后sessionFactory 就没有对应的get方法了
    因为HibernateDaoSupport 有一个同名字的final方法。而且我已经有很多个DAO了
      

  5.   

    你的sessionFactory中没有配置dataSource嘛?奇怪你怎么能手动提交成功的?
      

  6.   

    我基本上是从 http://www.360doc.com/content/10/0312/16/968587_18497905.shtml
    这里照搬  怎么弄dataSource? 那不是和hibernate.cfg.xml 中的配置重复了?
      

  7.   

    我知道了public Session getSession() {
    return sf.getCurrentSession();
    }  不能直接openSession
      

  8.   

    hibernateDaoSupport是必须要继承的!!!