public void add()//PROPAGATION_NEVER不应在事务中进行
{
addPerson.addUser();//PROPAGATION_SUPPORTS支持现在的事务,没有就非事务进行
addPerson.addPerson();//PROPAGATION_REQUIRED表示在目前的事务中执行操作,如果事务不存在就建立一个新的事务。
}是否逻辑有些混乱啊

解决方案 »

  1.   

    要不在
    <prop key="addPerson">PROPAGATION_REQUIRED</prop>
    加上+Exception试试,感觉你的逻辑比较乱了。。
    <prop key="addPerson">PROPAGATION_REQUIRED,+xxxException</prop>
      

  2.   

    老兄,我在测试事务属性
    PROPAGATION_NEVER
    PROPAGATION_
    PROPAGATION_REQUIRED
    区别而已,如果按照它们字面的意思,
    好象不应该这样的
      

  3.   

    我知道你在弄复合的事务属性,但是对于一般常用的事务来说,复合事务的确比较难以控制。
    你可以试试编程式事务的操作。http://spring.jactiongroup.net/viewtopic.php?t=2182
      

  4.   

    提交公告:关于Spring中声明式或编程式嵌套事务的讨论
      

  5.   

    奇怪啊,我做的测试是符合配置期望的:Hibernate: insert into T_Item      // 第一个方法的数据库写入sql
    11:14:01,281  WARN HibernateTransactionManager:601 - Should roll back transaction but cannot - no transaction available    //然后抛出了这个警告,第一个方法写入的数据没有被回滚。
        <bean id="es"
              class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager" ref="transactionManager"/>
            <property name="target" ref="exampleService"/>
            <property name="transactionAttributes">
                <props>
                    <prop key="add1">PROPAGATION_SUPPORTS</prop>
                    <prop key="add2">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>    <bean id="testAdd"
              class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager" ref="transactionManager"/>
            <property name="target" >
                <bean class="com.saro.example.web.TestAdd" >
                    <property name="es" ref="es" />
                </bean>
            </property>
            <property name="transactionAttributes">
                <props>
                    <prop key="add">PROPAGATION_NEVER</prop>
                </props>
            </property>
        </bean>楼主把你的完整配置和代码贴出来看看。
      

  6.   

    public class TestAdd {    public void add(){
            this.es.add1();
            this.es.add2();
        }    private ExampleService es;    public void setEs(ExampleService es) {
            this.es = es;
        }
    }
      

  7.   

    我想可能是这样    <bean id="trantTest" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <property name="target"><ref local="trantTestTarget"/></property>你这里的trantTestTarget使用的不是你配置的那个addPerson(有事务增强的bean)而是new了一个AddPerson?