ssh中事务没有被管理上,总是自动提交

application.xml



<!-- hibernate配置文件 -->


<!--方言-->
${dialect}
<!--显示sql-->
${show_sql}
<!--格式化sql-->
${format_sql}

            <prop key="hibernate.current_session_context_class">${thread}</prop>

            <prop key="hibernate.transaction.factory_class">${transaction}</prop>
        </props>
    </property>
    <property name="mappingResources">
        <list>
            <value>module/test/entity/Test.hbm.xml</value>
            <value>module/tree/entity/SsfFaLocation.hbm.xml</value>
            <value>module/base/user/entity/BaseUser.hbm.xml</value>
        </list>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Throwable,java.lang.Exception" />
        <tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Throwable,java.lang.Exception"/>
        <tx:method name="update*" propagation="REQUIRED"  rollback-for="java.lang.Throwable,java.lang.Exception"/>
        <tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
        <tx:method name="doGet*" propagation="REQUIRED" rollback-for="java.lang.Throwable,java.lang.Exception"/>
        <!--test-->
        <tx:method name="test" propagation="REQUIRED" rollback-for="java.lang.Throwable,java.lang.Exception" />
        <tx:method name="upload*" propagation="REQUIRED" rollback-for="java.lang.Throwable,java.lang.Exception"/>
    </tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
    <!--没切上 只切的到了一个类  execution(* util..*.*(..))
        第二个测试daoImpl   execution(* module.test.dao.DemoDaoImpl.test(..)) or
        -->
    <aop:pointcut id="allServiceMethod" expression="(execution(* module.*.service..*.*(..)) or
                                                     execution(* module.base.*.service.*.*(..))
                                                     )"/>
    <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/>
</aop:config>

Test1 t = new Test1();
        t.setTid("656");
        t.setTname("玉兔");
        saveEntity(t);

        Test1 t1 = new Test1();
        t1.setTid("799");
        t1.setTname("bbf");
        saveEntity(t1);
        throw new RuntimeException("报错吧");

public void saveEntity(T o) {
    Assert.notNull(o);
    getHibernateTemplate().saveOrUpdate(o);
    log.info("save entity:"+o);
}

    保存第一条就提交到数据库了 这是怎么回事啊

是你理解的有问题。它的事务管理是说它的事务在Dao层执行,离开Dao层就没有了;


这个才是事物的切面,只有这这个配置的包下的类或类里面的方法才有事物,离开了就没有事物。其中*表示的是通配符


这个才是事物的切面,只有这这个配置的包下的类或类里面的方法才有事物,离开了就没有事物。其中*表示的是通配符

保存第一条本来就提交到数据库了,,