刷新/访问更新Spring中事务外的实体

时间:2018-01-05 10:49:51

标签: spring hibernate transactions spring-transactions transactionscope

我在new Spring事务中生成readonly Spring事务。新事务正在DB中创建一个条目。在退出新事务后,我能够获取readonly事务中的数据,尽管此时已在数据库中创建了条目。

    Interface A {
      @Transactional(readOnly = true)
      void methodA();
    }

    Interface B {
      @Transactional(propagation = Propagation.REQUIRES_NEW)
      void methodB();
    }

    Class classA implements A {
      public void methodA() {
            classB.methodB();
            // select * from Employee where id = 1
            // Problem: This returns nothing, maybe because it belongs to different transaction. 
            // >>>>>>>>>>> How can i access it here <<<<<<<<<<<<
        }
    }


    Class classB implements B {
      public void methodB() {
             // Code to: insert into table Employee(id) values(1);
        }
    }

0 个答案:

没有答案