users@jersey.java.net

Re: Cannot use an EntityTransaction while using JTA, cannot switch to application managed transactions

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 08 Apr 2008 11:39:00 +0200

Hi Jacob,

to me it seems as a Netbeans REST plugin issue
rather than a Jersey issue.

Could you please try to submit a new issue record at
http://www.netbeans.org/issues

Component: websvc
Subcomponent: rest

It would also help if you could attach your (zipped)
NetbeansProject there.

Thanks,

~Jakub



On Tue, Apr 08, 2008 at 10:43:36AM +0200, Jacob wrote:
> Hi All,
>
> I am using Netbeans to develop RESTful web services (using JAX-RS) on
> top of entity beans anotated in JPA and persisted in MySQL. I tried
> the built-in netbeans wizard to generate restful ws from entity beans.
> However, when I try to access the web service I get a following
> exception:
>
> java.lang.IllegalStateException:
> Exception Description: Cannot use an EntityTransaction while using JTA.
>
>
>
> Indeed I'm using JTA in my persistence.xml, does it automatically mean
> that I cannot use EntitytTransaction? If so, how do I persist and
> merge objects? I cannot do it without a transaction because I'm
> getting:
>
> javax.persistence.TransactionRequiredException
>
>
>
> I tried switching to application-managed transactions (and using the
> UserTransaction instead of EntityTransaction) but I cannot get the
> persistence unit to work. If I substitute the auto-genereated thread
> local based PersistenceService and annotate my class with the
> following:
>
> @PersistenceUnit(unitName = "localindexes")
> private EntityManagerFactory emf;
>
> private EntityManager getEntityManager() {
> return emf.createEntityManager();
> }
>
> @Resource
> private UserTransaction utx;
>
>
> I get yet another exception:
>
> javax.servlet.ServletException:
> com.sun.ws.rest.api.container.ContainerException: Persistence unit
> 'localindexes' is not configured as a servlet parameter in web.xml
>
>
> Putting:
>
> <persistence-context-ref>
> <description>Persistence context for the web services</description>
> <persistence-context-ref-name>persistence/localindexes</persistence-context-ref-name>
> <persistence-unit-name>localindexes</persistence-unit-name>
> </persistence-context-ref>
>
>
>
> in the web.xml or annotating the ws class with
> @PersistenceContext(name = "persistence/localindexes", unitName =
> "localindexes") does not help at all.
>
> I'm already tearing my hair out so any help would be appreciated.
> Thanks in advance.
>
> my persistence.xml uses toplink as a persistence provider:
>
> <persistence-unit name="localindexes" transaction-type="JTA">
> <provider>oracle.toplink.essentials.PersistenceProvider</provider>
> <jta-data-source>mysql-localhost</jta-data-source>
> <exclude-unlisted-classes>false</exclude-unlisted-classes>
> <properties>
> <property name="toplink.ddl-generation" value="create-tables"/>
> </properties>
> </persistence-unit>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>