Uploaded image for project: 'Aries'
  1. Aries
  2. ARIES-2050

Aries JPA 2.7 shouldn't always reuse EM instance from previous coordinations

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • jpa-2.7.2
    • jpa-2.7.3
    • JPA
    • None

    Description

      I have a scenario consisting of the following call graph:

      testService.performTest() [ @Transactional(TxType.REQUIRED) ]
      +-- List<Car> cars = carDao.getAllCars()
      |   +-- return em.createQuery("select c from Car c", Car.class).getResultList()
      |       (em is injected using @PersistenceContext(unitName = "xa-test-unit"))
      |
      +-- carDao.createNew(car);
      |   +-- em.persist(car);
      |
      +-- newTxTestService.testNewTransaction(transactionManager.getTransaction()) [ @Transactional(TxType.REQUIRES_NEW) ]
          +-- List<Car> cars = carDao.getAllCars();
              +-- return em.createQuery("select c from Car c", Car.class).getResultList()
      

      The problem is that inside the method marked with @Transactional(TxType.REQUIRES_NEW) the em proxy uses the same underlying em instance because of:

      Coordination getTopCoordination() {
          Coordination coordination = coordinator.peek();
          while (coordination != null && coordination.getEnclosingCoordination() != null) {
              coordination = coordination.getEnclosingCoordination();
          }
          return coordination;
      }
      

      And even if the suspended transaction is not yet committed, the em returns the persisted (but not yet committed) cars.

      The coordination stack consists of (names of coordination objects):

      • txInterceptor.org.apache.aries.jpa.container.itest.bundle.blueprint.impl.TestServiceImpl.performTest
      • txInterceptor.org.apache.aries.jpa.container.itest.bundle.blueprint.impl.NewTxTestServiceImpl.testNewTransaction
      • jpa

      the top coordination contains em variable associated with suspended transaction.

      I'm working on a solution that properly assigns current em respecting tx-demarcated coordinations.

      cschneider, gnodet, jbonofre if you have an idea about the best solution, please share.

      For now I think both aries-jpa and aries-blueprint-transaction have to be fixed (the latter one should put some magical variable to the coordination objects pushed inside org.apache.aries.transaction.TxInterceptorImpl)

      Attachments

        Issue Links

          Activity

            People

              ggrzybek Grzegorz Grzybek
              ggrzybek Grzegorz Grzybek
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: