14 Replies Latest reply: Aug 6, 2014 3:48 PM by Scott Marlow RSS

TransactionScopedPersistenceContext -  EntityManager is not reused when transaction returns home

Epi Salamanca Newbie

Hi I'm currently running JBoss EAP 6.0.1, which is based on

 

- jboss-as-ejb3-7.1.3.Final-sources

- jbossjts-4.16.6.Final-sources

- jboss-as-jpa-7.1.3.Final-sources

- jboss-as-jpa-hibernate4-7.1.3.Final-sources

 

and using as datasource the example H2 xa resource.

 

I have 2 ear:

 

- A and B ( deployed in different JBoss container )

 

Ear  A contains the following EJBs

 

- EJB1, Stateless, implements @Local and @Remote ( The only one that access the underlying database )

  - EJB2, Stateless, implements @Local

  - WAR, UI based on primefaces, offers a form to trigger the test case.

 

Ear B contains the following EJBs

 

-EJB3, Stateless, implements @Remote

 

The test case is as follows:

 

0- Transaction is Managed by the container.

 

1 -Client calls a method in EJB1 via the @Local interface -- transaction is open              - method using the default behaviour for @TransactionAttribute

2 -EJB1 retrieves entity Book from databases

3- EJB1 updates attribute in entity Book

4 -EJB1 makes a synchronous call to EJB2 -- (transaction is propagated)                       - method annotated with @TransactionAttribute(TransactionAttributeType.MANDATORY)

5- EJB2 locates remote EJB3 and invokes methods in EJB3 (transaction is propagated)  - method annotated with @TransactionAttribute(TransactionAttributeType.MANDATORY)

6- EJB3 locates remote EJB1 and invokes methods in EJB1 (transaction is propagated)  - method annotated with  @TransactionAttribute(TransactionAttributeType.MANDATORY)

7- EJB1 retrieves entity Book and gets the value set for attribute (transaction is propagated and entity manager is not being reused)

 

 

The value of the attribute in step 7, is different from the value of the attribute that was set in step 3.

 

I was expecting, that the persistence context to be shared among the entity managers when transaction returns_home.

 

 

Is the behaviour observed the expected behaviour ?

 

If no, is this then a bug ?

if yes, is there a way to achieve the sharing of the persistence context whithin a transaction scoped persistence context ?

 

 

Thanks,

Epi

 

 

 

 

===================================================================================================================

 

 

A and B deployed in different container
================================================================================================================================================================================
 1- 09:18:33,708 INFO  [stdout] (http-/0.0.0.0:8080-2) Called execute
 2- 09:18:33,708 INFO  [stdout] (http-/0.0.0.0:8080-2) flush:false
 3-09:18:33,708 INFO  [stdout] (http-/0.0.0.0:8080-2) tcId:remote
 4-09:18:33,709 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: created entity manager session TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
 5-09:18:33,710 TRACE [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) createQuery took 1ms
 6-09:18:33,713 INFO  [stdout] (http-/0.0.0.0:8080-2) Hibernate: select book0_.id as id5_, book0_.author as author5_, book0_.isbn as isbn5_, book0_.publishedYear as publishe4_5_, book0_.title as title5_ from Book book0_ where book0_.isbn like ?
 7-09:18:33,716 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
 8-09:18:33,716 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
 9-09:18:33,717 TRACE [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) find entityClass 'com.sample.model.Book' took 1ms
10-09:18:37,134 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
11-09:18:37,135 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
12-09:18:37,135 TRACE [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) find entityClass 'com.sample.model.Book' took 1ms
13-09:18:37,135 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: em.toString() : org.jboss.as.jpa.container.TransactionScopedEntityManager@274a1f68
14-09:18:37,136 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
15-09:18:37,136 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: em.unwrap(org.hibernate.ejb.EntityManagerImpl.class).toString() : org.hibernate.ejb.EntityManagerImpl@1e36ed62
16-09:18:37,136 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: Initial Value 2004
17-09:18:37,137 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: new value for att:publishedYear:2013
18-09:18:38,333 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
19-09:18:38,334 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
20-09:18:38,334 TRACE [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) find entityClass 'com.sample.model.Book' took 1ms
21-09:18:38,335 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: em.toString() : org.jboss.as.jpa.container.TransactionScopedEntityManager@274a1f68
22-09:18:38,335 DEBUG [org.jboss.as.jpa] (http-/0.0.0.0:8080-2) http-/0.0.0.0:8080-2:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e04 status: ActionStatus.RUNNING >
23-09:18:38,335 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: em.unwrap(org.hibernate.ejb.EntityManagerImpl.class).toString() : org.hibernate.ejb.EntityManagerImpl@1e36ed62
24-09:18:38,336 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: em.toString() : org.jboss.as.jpa.container.TransactionScopedEntityManager@274a1f68
25-09:18:38,336 INFO  [com.sample.ejb.Bean2Impl] (http-/0.0.0.0:8080-2) Context initialised
26-09:18:38,337 INFO  [com.sample.ejb.Bean2Impl] (http-/0.0.0.0:8080-2) Bean3 located
27-09:18:42,383 DEBUG [org.jboss.as.jpa] (EJB default - 10) EJB default - 10:[transaction scoped EntityManager]: created entity manager session TransactionImple < jca-subordinate, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e0c status: ActionStatus.RUNNING >
28-09:18:42,384 DEBUG [org.jboss.as.jpa] (EJB default - 10) EJB default - 10:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < jca-subordinate, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e0c status: ActionStatus.RUNNING >
29-09:18:42,386 INFO  [stdout] (EJB default - 10) Hibernate: select book0_.id as id5_0_, book0_.author as author5_0_, book0_.isbn as isbn5_0_, book0_.publishedYear as publishe4_5_0_, book0_.title as title5_0_ from Book book0_ where book0_.id=?
30-09:18:42,389 TRACE [org.jboss.as.jpa] (EJB default - 10) find entityClass 'com.sample.model.Book' took 6ms
31-09:18:42,389 INFO  [com.sample.ejb.Bean1Impl] (EJB default - 10) Bean1: em.toString() : org.jboss.as.jpa.container.TransactionScopedEntityManager@31d1f1d
32-09:18:42,390 DEBUG [org.jboss.as.jpa] (EJB default - 10) EJB default - 10:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < jca-subordinate, BasicAction: 0:ffff0a2def9a:-2b649b8:520b9c50:e0c status: ActionStatus.RUNNING >
33-09:18:42,390 INFO  [com.sample.ejb.Bean1Impl] (EJB default - 10) Bean1: em.unwrap(org.hibernate.ejb.EntityManagerImpl.class).toString() : org.hibernate.ejb.EntityManagerImpl@8c100c1
34-09:18:42,395 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: localValue := 2013
35-09:18:42,396 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) Bean1: remoteValue := 2004
36-09:18:42,396 INFO  [com.sample.ejb.Bean1Impl] (http-/0.0.0.0:8080-2) TEST - FAILED
37-09:18:42,397 INFO  [stdout] (http-/0.0.0.0:8080-2) Hibernate: update Book set author=?, isbn=?, publishedYear=?, title=? where id=?
================================================================================================================================================================================