This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
On behalf of External User (Jacob <skoczko@gmail.com>) ========================== Subject: Cannot use an EntityTransaction while using JTA, cannot switch to application ma 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> =====================
Workaround: Temporary solution I found is to look-up the EntityManager and UserTransaction in the container: private EntityManager getEntityManager() { EntityManager em = null; try { em = (EntityManager) new InitialContext().lookup("java:comp/env/persistence/localindexes"); } catch (NamingException e) { Logger.getLogger(HarvestablesResource.class.getName()).log(Level.SEVERE, null, e); } return em; } private UserTransaction getUserTransaction() { UserTransaction utx = null; try { utx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction"); } catch (NamingException e) { Logger.getLogger(HarvestablesResource.class.getName()).log(Level.SEVERE, null, e); } return utx; } However, I would still very much like to get the annotations to work.
Starting with NB 6.1 milestone 1, if you are running against a container such as glassfish which supports JTA, the generated CRUD app will use JNDI lookup to look up an instance of UserTransaction and use it for transaction processing . If you are running against Tomcat without any JTA support installed, the generated CRUD app will continue to use EntityTransaction.
TM says 6.0M1, your (Peter's) comment says 6.1M1 and I saw some change(s)[1] perhaps related to this which will become visible in 6.5M1... So what's the correct TM here?
forgotten reference: [1]: http://hg.netbeans.org/main?cmd=changeset;node=8792e429b881
Oops, I meant to select 6.5m1.