this.getHibernateTemplate().save(news);
是不是事物没提交?

解决方案 »

  1.   

    我估计是你的数据源的配置有问题,datasource 节点。应该有一个 "自动提交“属性,你看你设置为多少了。而且这里还有很多的属性,包括只读等,都有默认值,你看下,你有没有对他们进行设置。
      

  2.   

    boolean istrue=this.getHibernateTemplate().save(news);if(istrue){System.out.println("成功!");
    }else{
    System.out.println("失败!");
    }
      

  3.   

    是否用了opensessionview
    如果配置不好会插不进去
      

  4.   

    这个试试?
    <!-- 事务管理器 -->
    <bean name="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>

    <!-- 事务属性源 -->
    <bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
    <property name="properties">
    <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="write*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    <!-- 自动代理事务 -->
    <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
    </bean> <!-- 事务Advisor -->
    <bean id="transactionAdvisor" class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
    <constructor-arg>
    <ref bean="transactionInterceptor"/>
    </constructor-arg>
    </bean> <!-- 事务拦截器 -->
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager">
    <ref bean="transactionManager"/>
    </property>
    <property name="transactionAttributeSource">
    <ref bean="transactionAttributeSource"/>
    </property>
    </bean>

    <!-- 事务Advisor -->
    <bean id="transactionAdvisor" class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
    <constructor-arg>
    <ref bean="transactionInterceptor"/>
    </constructor-arg>
    </bean> <bean id="" class="">
    <!-- 以后添加bean就可以了 容器会自动对bean合适的方法进行事务拦截 -->
    </bean>
      

  5.   

    问一下楼上的大哥,你的代码是全都加到applicationContext.xml中吗?
      

  6.   

    关注中,帮忙顶 
    欢迎加入群20026593  java学习
      

  7.   

    这个问题我也遇到过
    解决方法是把数据源也定义在applicationContext.xml中