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
- is broken by
-
ARIES-1346 EntityManager should be reused for series of coordinated calls
- Resolved
- is related to
-
ARIES-1362 Support coordinations triggered by transaction markers
- Resolved
- relates to
-
ARIES-2075 transaction-blueprint Coordinations should check existing TX
- Closed
- links to