你连接JDBC的配置呢?
 <property name="defaultAutoCommit">
设置成true就可以了。

解决方案 »

  1.   

    <bean id="dataSource_log_mysql" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
                <value>${jdbc_log_mysql.driverClassName}</value>
            </property>
            <property name="url">
                <value>${jdbc_log_mysql.url}</value>
            </property>
            <property name="username">
                <value>${jdbc_log_mysql.username}</value>
            </property>
            <property name="password">
                <value>${jdbc_log_mysql.password}</value>
            </property>
             <property name="initialSize">
                <value>${jdbc_log_mysql.initialSize}</value>
            </property>
             <property name="maxActive">
                <value>${jdbc_log_mysql.maxActive}</value>
            </property>
             <property name="maxIdle">
                <value>${jdbc_log_mysql.maxIdle}</value>
            </property>
             <property name="defaultAutoCommit">
                <value>${jdbc_log_mysql.defaultAutoCommit}</value>
            </property>      
    </bean>
      

  2.   

    首先谢谢这位大哥,但是还是没成功。
    我的数据库配置文件是myeclipse自动生成的,没有设置defaultAutoCommit,于是我在hibernate.cfg.xml中加上了<property name="defaultAutoCommit">true</property>。
    但是不论是true还是false都不行。在补上hibernate的配置文件(已加上defaultAutoCommit后的)<?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.Oracle9Dialect
    </property>
    <property name="connection.url">jdbc:oracle:thin:@192.168.1.3:1521:am8</property>
    <property name="connection.username">am8</property>
    <property name="connection.password">english</property>
    <property name="connection.driver_class">
    oracle.jdbc.driver.OracleDriver
    </property>
    <property name="defaultAutoCommit">true</property>
    <property name="myeclipse.connection.profile">8amtest</property>
    <mapping resource="www/am8/pojo/Test.hbm.xml" /> </session-factory></hibernate-configuration>
      

  3.   

    你没有采用Spring为Hibernate提供的getHibernateTemplate() 方法啊也,
    你那么用只是用了Spring的注入,根本也没让Spring去托管Hibernate,所以你配置的事务切面怎么会有效果。
      

  4.   

    应该是有使用吧?因为我调用了testDAO.getHibernateTemplate().getSessionFactory().close();之后就能在数据库里看到了。能调用这句应该就是已经托管了吧?
      

  5.   

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

    <!--配置事务  -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- 配置通知 -->
    <tx:advice id="txAdvice">
    <tx:attributes>
    <tx:method name="find*" read-only="true"/>
    <tx:method name="*"/>
    </tx:attributes>
    </tx:advice>
    <!-- 配置通知器 -->
    <aop:config>
    <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.svse.service.*Service.*(..))"/>
    </aop:config>


    <bean id="usersDao" class="com.svse.dao.hibernate.UsersDaoHibernate">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="usersService" class="com.svse.service.impl.UsersServiceImpl">
    <property name="usersDao" ref="usersDao"></property>
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
      

  6.   

    来向大家汇报一下最新情况:
    采用了1楼romantic112的方法设置成<property name="defaultAutoCommit"><value>true</value></property>之后是会提交了,但是事务却无法回滚了。
    而设置成false就无法自动提交。然后7楼andy_swc的方法,我本来就有设置,不过我还是把andy_swc的代码考到我的配置文件里,依然和最初的问题一样不提交,defaultAutoCommit设置成true就提交,但是无法回滚。现在怀疑是否是spring没有能够代理到事务管理呢?
    附上最新的事务配置信息,知道的朋友帮我看看吧!<?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.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    <!-- bonecp --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
                <value>oracle.jdbc.driver.OracleDriver</value>
            </property>
            <property name="url">
                <value>jdbc:oracle:thin:@192.168.1.3:1521:am8</value>
            </property>
            <property name="username">
                <value>am8</value>
            </property>
            <property name="password">
                <value>english</value>
            </property>
             <property name="initialSize">
                <value>0</value>
            </property>
             <property name="maxActive">
                <value>30</value>
            </property>
             <property name="maxIdle">
                <value>10</value>
            </property>
             <property name="defaultAutoCommit">
                <value>true</value>
            </property>
    </bean>  <!-- 配置sessionFactory, 为Hibernate配置属性 --> <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource" /> </property>    <property name="configLocation"> 
            <value>classpath:hibernate.cfg.xml</value> 
           </property>     <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>
    </tx:attributes>
    </tx:advice> <aop:config >
    <aop:pointcut id="allManagerMethod" expression="execution(* www.am8.manage.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
    </aop:config>

    <bean id="TestManageImpl" class="www.am8.manage.TestManageImpl">
    <property name="iTestDAO">
    <ref bean="TestDAO" />
    </property>
    </bean>

    <bean id="TestDAO" class="www.am8.pojo.TestDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="GuanLianDAO" class="www.am8.pojo.GuanLianDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    </beans>
      

  7.   

    貌似现在很多人是用自动代理对象.至于hibernate事务提交好像是自动进行的,只需要调用sping生成的对象
      

  8.   

    请问defaultAutoCommit设置为false,事务不提交
    设置为true,不回滚
    这个问题怎么解决啊·· 求教 
      

  9.   

    将sessionFactory.openSession();改为sessionFactory.getCurrentSession();,默认sessionFactory.getCurrentSession();获取的Session是可以自动提交的!