users@glassfish.java.net

Re: Cannot use an EntityTransaction while using JTA.

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Tue, 27 Mar 2007 17:27:40 -0400

I don't know if NetBeans is buggy or not.. I don't understand what I'm
supposed to do to solve this problem.

I inject the entity manager like this:

 @PersistenceContext(unitName="MyPU")
    private EntityManager em;


Thanks,
Ryan


Marina Vatkina wrote:
> Hi Ryan,
>
> Removing transaction-type doesn't make a difference - it's JTA by
> default in a Java EE environment. If NetBeans doesn't work correctly,
> please file a bug with NetBeans directly.
>
> How do you get a hold of EM? Do you
> a) call Persistence.createEMF()
> b) inject or look up EMF
> c) inject or look up EM
>
> thanks,
> -marina
>
> Ryan de Laplante wrote:
>> Hi,
>>
>> I have a Java 5 web application who's only purpose is to provide a
>> web service. The web service uses JPA to read an entity from the
>> database, make a change and save it back into the db. Because this
>> is not an EJB, I have to manually begin and commit a transaction for
>> persist() to work.
>>
>> When I do the following, the app server throws an
>> IllegalStateException ("Cannot use an EntityTransaction while using
>> JTA.")
>>
>> EntityTransaction trans;
>> trans = em.getTransaction();
>>
>>
>> I opened my persistence.xml in NetBean's visual editor, unchecked
>> "Use Java Transaction APIs", then saved and redeployed. This did not
>> make a difference. I noticed a transaction-type="JTA" attribute was
>> still on the <persistence-unit> element so I removed it, saved and
>> redeployed. I still get an exception.
>>
>>
>> Thanks,
>> Ryan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>