users@glassfish.java.net

Re: embedded ejb container - JTA and entity managers

From: Phillip Ross <phillip.w.g.ross_at_gmail.com>
Date: Thu, 3 Mar 2011 13:30:11 -0500

Thanks Marina, I tried with the name you provided but have the same problem.
 I was able to lookup a user transaction object with that name, but I get
the same exception. The entity manager doesnt seem to know about the
transaction manager. I'm wondering if maybe I should cross post this issue
to the eclipselink mailing lists. I know 3.1 ups the eclipselink version to
2.2, so that's also a difference between 3.0.1 and 3.1.

Thanks again
- Phillip

On Thu, Mar 3, 2011 at 1:07 PM, Marina Vatkina <marina.vatkina_at_oracle.com>wrote:

> "UserTransaction" is not the right lookup name. We allowed it for some
> time, but decided against it in 3.1. Try the spec defined
> "java:comp/UserTransaction".
>
> -marina
>
>
> Phillip Ross wrote:
>
>> Hi all,
>>
>> I'm still attempting to update test code from 3.0.1 to 3.1 and am running
>> into a new set of issues. In 3.0 I was able to define a single
>> persistence.xml with a persistence unit defining a transaction-type of JTA.
>> When running with the embedded EJB container, I was able to lookup EJBs
>> that had entity managers injected and use the entity managers inside the
>> EJBs with container managed transactions. I was ALSO able to lookup the JTA
>> UserTransaction object outside of an EJB, and create an entity manager using
>> the javax.persistence.Persistence class which would look something like the
>> following:
>>
>> UserTransaction userTransaction =
>> (UserTransaction)context.lookup("UserTransaction");
>> EntityManager entityManager =
>> Persistence.createEntityManagerFactory("default").createEntityManager();
>>
>> This entityManager was able to work alongside of the userTransaction to
>> execute JTA-based user managed transactions and JPA persistence:
>>
>> userTransaction.begin();
>> entityManager.joinTransaction();
>> entityManager.persistence(someEntity);
>> userTransaction.commit();
>>
>> So the transaction management and entity persistence seemed to be
>> integrated nicely in the embedded container for 3.0. As of 3.1, the code
>> now generates exceptions when trying to have the entity manager join the
>> transaction:
>>
>> javax.persistence.TransactionRequiredException: Exception Description: No
>> transaction is currently active
>> at
>> org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.throwCheckTransactionFailedException(EntityTransactionWrapper.java:113)
>> at
>> org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.checkForTransaction(EntityTransactionWrapper.java:50)
>> at
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:1666)
>> at
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.joinTransaction(EntityManagerImpl.java:1698)
>>
>> It appears to be the case that the persistence context and transaction
>> manager can no longer find each other in 3.1.
>>
>> Do I have to do something extra as of v3.1 to get the persistence contexts
>> integrated with the transaction manager?
>>
>> Thanks
>> - Phillip
>>
>>