spring集成jta中设置readonly意思?? 既是 配置多数据源设置 使用 spring ibatis jta  jotm设置后  <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" /> <bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="jotm" />
</bean>然后设置
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="select*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
然后我在service 中调用  以   do开头的方法执行 插入 操作,依旧能成功??
public void testAddCustomer() throws Exception {
TestService cm = (TestService)factory.getBean("testService");
for(int i=0; i<1; i++){
User u = new User();
u.setId(i+"");
u.setName("name"+i);
u.setPass("pass"+i);
// cm.addUser(u);
// cm.addUser2(u);
// cm.doUser(u);
// cm.doUser2(u);
// cm.addUser3(u);
cm.doUser3(u);
}
}
现在问题出来了:为什么 <tx:method name="*" read-only="true" />没有起作用  ,还是我把 read-only的 意思理解错了  请解答 谢谢

解决方案 »

  1.   

    如果你加上 <tx:method name="testAdd*" read-only="true" />应该就行了..我也不是很明白这个..按道理应该是除以上required之外剩余的都是read-only,同求高手呵
      

  2.   

    不用加了!
    public void testAddCustomer() throws Exception {
            TestService cm = (TestService)factory.getBean("testService");
            for(int i=0; i<1; i++){
                User u = new User();
                u.setId(i+"");
                u.setName("name"+i);
                u.setPass("pass"+i);
    //            cm.addUser(u);
    //            cm.addUser2(u);
    //            cm.doUser(u);
    //            cm.doUser2(u);
    //            cm.addUser3(u);
                cm.doUser3(u);        }
        }
    这里才是service层public class CustomerManagerTest extends TestCase { private static BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");

    public void testAddCustomer() throws Exception {
    TestService cm = (TestService)factory.getBean("testService");
    for(int i=0; i<1; i++){
    User u = new User();
    u.setId(i+"");
    u.setName("name"+i);
    u.setPass("pass"+i);
    // cm.addUser(u);
    cm.doUser(u);
    // cm.addUser2(u);
    // cm.doUser2(u);
    // cm.addUser3(u);
    // cm.doUser3(u);
    // JtaTransactionManager
    }
    }public class TestServiceImpl implements TestService {

    private TestDao testDao;
    private TestDao testDao2;
    @Override
    public void doUser(User u) {
    // TODO Auto-generated method stub

    this.testDao.addUser(u);

    throw new RuntimeException("doUser");


    }
    <aop:config>
    <aop:pointcut id="serviceOperation" expression="execution(* com.wsd.service.*.*(..))" />
    <aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice" />
    </aop:config> <!-- <aop:config proxy-target-class="true"> <aop:pointcut id="serviceOperation" 
    expression="execution(* com.wsd.service.*.*(..))" /> <aop:advisor pointcut-ref="serviceOperation" 
    advice-ref="txAdvice" /> </aop:config> --> <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
    <tx:method name="*" read-only="true" />
    </tx:attributes>
    </tx:advice>如果我使用 jta 但是使用hibernate, readonly 是不能进行修改的,
    如果使用 jta 使用ibatis readonly ,我执行修改依旧能成功
    如果使用 但数据源 不是jta 使用 ibatis  ,readonly 也是不能修改的

    所以就不知道怎么修改,求解
      

  3.   

    上面一个忘记注释了:
    public class TestServiceImpl implements TestService {
        
        private TestDao testDao;
        private TestDao testDao2;
            @Override
        public void doUser(User u) {
            // TODO Auto-generated method stub
            
            this.testDao.addUser(u);
            
            
    //throw new RuntimeException("doUser");
    //这个抛异常可以回滚,如果抛异常, doUser方式本来是 readonly的,但是这里也能执行插入
        
            
        }