users@jpa-spec.java.net

[jpa-spec users] [jsr338-experts] Re: question about transactional scoped versus extended persistence context in section 7.9.1 (container responsibilities)

From: Linda DeMichiel <linda.demichiel_at_oracle.com>
Date: Tue, 21 Feb 2012 20:53:12 -0800

Hi Scott,

On 2/21/2012 6:44 PM, Scott Marlow wrote:
> Hi,
>
> In section 7.9.1, we currently have the wording:
>
> "
> For the management of a transaction-scoped persistence context, if there is no EntityManager already
> associated with the JTA transaction:
>
> * The container creates a new entity manager by calling EntityManagerFactory.createEntityManager when the first
> invocation of an entity manager with PersistenceContextType.TRANSACTION occurs within the scope of a business method
> executing in the JTA transaction.
>
> ...
>
> For stateful session beans with extended persistence contexts:
>
> ...
>
> * When a business method of the stateful session bean is invoked, if the stateful session bean uses container managed
> transaction demarcation, and the entity manager is not already associated with the current JTA transaction, the
> container associates the entity manager with the current JTA transaction and, if the persistence context is of type
> SynchronizationType.SYNCHRONIZED, the container calls EntityManager.joinTransaction. If there is a different persistence
> context already associated with the JTA transaction, the container throws the EJBException.
> ...
> "
>
> My question is about the extended persistence context part. Do we require the container to associate the entity manager
> with the JTA transaction, at the time that the stateful session bean is invoked or instead when the entity manager is
> invoked in the stateful session bean? I just wanted to make sure that this section is clearly stating the intended
> container requirement.
>

I think the spec is pretty clear that it should be the former. I think this is also the correct
behavior -- i.e., if managed entities were updated without a call to the entity manager,
updates could otherwise be lost.

-Linda


> Scott