You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltaspike.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2018/09/03 10:31:00 UTC

[jira] [Commented] (DELTASPIKE-900) ResourceLocalTransactionStrategy not working with multiple EntityManagers

    [ https://issues.apache.org/jira/browse/DELTASPIKE-900?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16601996#comment-16601996 ] 

ASF subversion and git services commented on DELTASPIKE-900:
------------------------------------------------------------

Commit 779d28b39c267b960ebb65ab3187c63033f7c834 in deltaspike's branch refs/heads/master from [~struberg]
[ https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;h=779d28b ]

DELTASPIKE-900 proper EntityManager setup


> ResourceLocalTransactionStrategy not working with multiple EntityManagers
> -------------------------------------------------------------------------
>
>                 Key: DELTASPIKE-900
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-900
>             Project: DeltaSpike
>          Issue Type: Bug
>          Components: JPA-Module
>    Affects Versions: 1.2.1, 1.3.0
>            Reporter: Johannes Testori
>            Assignee: Mark Struberg
>            Priority: Major
>
> We are using CDI-ApplicationScoped services in a batch program with CdiControl. We started using multiple qualified EntityManagers in a single service annotated with @Transactional and encountered the problem that database changes are not committed. After some debugging we found the problem in the "execute"-method in ResourceLocalTransactionStrategy.
> for (Class<? extends Annotation> emQualifier : emQualifiers)
> {
>     EntityManager entityManager = resolveEntityManagerForQualifier(emQualifier);
>     EntityManagerEntry entityManagerEntry = createEntityManagerEntry(entityManager, emQualifier);
>     transactionBeanStorage.storeUsedEntityManager(entityManagerEntry);
>     EntityTransaction transaction = getTransaction(entityManagerEntry);
>     if (!transaction.isActive())
>     {
>         beforeBegin(invocationContext, entityManagerEntry, transaction);
>         transaction.begin();
>     }
>     else if (isOutermostInterceptor)
>     {
>         outermostTransactionAlreadyExisted = true;
>     }
>     //don't move it before EntityTransaction#begin() and invoke it in any case
>     beforeProceed(invocationContext, entityManagerEntry, transaction);
> }
> A transaction is created for the first EntityManager. But since the same transaction is assigned to the other EntityManagers, "outermostTransactionAlreadyExisted" is set to true. This is the cause for the transaction not being committed afterwards:
> if (isOutermostInterceptor)
> {
>     if (!outermostTransactionAlreadyExisted)
>     {
>         // We only commit transactions we opened ourselfs.
>         // If the transaction got opened outside of our interceptor chain
>         // we must not handle it.
>         // This e.g. happens if a Stateless EJB invokes a Transactional CDI bean
>         // which uses the BeanManagedUserTransactionStrategy.
> We've seen this problem in version 1.2.1 and 1.3.0. (didn't try other versions).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)