在做一个j2se的东西 想使用Hibnate方便点,但是在构建完框架进行一个测试的时候,发现不能保存,但可以查询出来数据 public static void main(String[] args) { ApplicationContext conxt = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
BaseDao dao = (BaseDao) conxt.getBean("basedao"); Demp demp = new Demp();  
// 
demp.setDempNames("企划部");     

dao.save(demp);   
}我的Spring配置文件,这里只发关键部分,看看我的事物提交有没有问题, 我是重以前项目中扒下来的
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">
PROPAGATION_REQUIRED,-java.lang.Exception
</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

解决方案 »

  1.   

     补充一点,hibnarte insert 语句已经出来了,但数据库里 没有。
      

  2.   

    还是配置有问题!pointcut配置的正确吗?
    <aop:pointcut id="allManagerMethod" expression="execution(* com.zzq.oa.manager.*.*(..))"/>
      

  3.   

    <property name="hibernate.show_sql">true</property>
    这个配置一下看看啊,你的log4j没有配置hibernate的日志没有打出错误
      

  4.   

    我以前出这样问题,用日志文件打印出来看看啊,实际上没有commit发出了SQL
      

  5.   

    ,hibnarte insert 语句已经出来了,但数据库里 没有那么后面就没有啥异常吗?
      

  6.   

    insert语句出来了,没有提交成功吧
      

  7.   

      hibernate sql语句出来,但是数据库没有数据显示,基本是因为你的事务没有Commit!看下事务处理配置是否正确。
      

  8.   


    这位仁兄太正确了。。呵呵,,几年前我遇到过一个这样的问题。。
    解决方法就是,
    hibernate save 后,加一个 flush!
      

  9.   

    我之前也遇到这个问题。我的那个问题是因为save方法没有把事物提交,所以没保存到数据库。
    http://topic.csdn.net/u/20090906/11/c991d981-8792-4f69-bbac-83846cbbf3c7.html不知这个连接能不能用。我发的帖。现在已经解决了!不行你搜spring+hibernate能查询但不能插入删除修改 试试
    希望对你有帮助