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.
The problem in the J2EE persistence API implementation. Steps to reproduce. 1) Add GF 3.1 ( or 3.0.1 ) 2) Create JEE6 Web Project . 3) Create RESTful WS via wizard. 4) Don't change anything in generated classes. 5) Deploy and Test RESTful WS. As result there is an error. The problem is presence of injected attribute in the service classes: @Resource private javax.transaction.UserTransaction utx; It appears on j2e persistence API method usage : EntityManagerGenerator generator = new EntityManagerGenerator(facade, entityFQN); List<GenerationOptions> methodOptions = getMethodOptions(entityFQN, variableName); for (GenerationOptions each : methodOptions){ generator.generate(each, ContainerManagedJTAInjectableInEJB.class); } The latter method should generate ONLY EntityManager injection in the issue situation. But it generates also utx field .
see http://netbeans.org/bugzilla/show_bug.cgi?id=188821 only if it's EJB there should be no UserTransaction. Is it EJB in this case?
(Comment #10 From David Konecny 2010-08-16 00:21:21)
As I understand yes. The generated service class is Stateless session bean. But I have provided to you the usecase. Go through the steps and check it . In case of wrong J2EE persistence API usage please let me know WHAT exactly is incorrect in this usage. I'm not an expert in the JPA area. This code has not been changed for ages ( in the REST area). Some time ago the generated code was correct and all works fine for me. I've realized the problem only with the latest j2ee.persistence version.
Actually the situation is not so simple and is VERY strange. I'm able to reproduce it randomly. I've checked some previous NB versions and UserTransaction field has been generated in early versions also. After this I've checked the project with GF3.1 It DOES work. Then I switched to GF3.0.1 After this the same application throw an error on GET HTTP request : exception javax.servlet.ServletException: javax.ejb.CreateException: Could not create stateless EJB root cause javax.ejb.CreateException: Could not create stateless EJB root cause com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Env-Prop: service.CustomerFacadeREST/utx@Field-Injectable Resource. Class name = service.CustomerFacadeREST Field name=utx@java.lang.String@java:comp/UserTransaction@@ into class service.CustomerFacadeREST root cause javax.naming.NamingException: Lookup failed for 'java:comp/env/service.CustomerFacadeREST/utx' in SerialContext [Root exception is javax.naming.NamingException: Lookup failed for 'java:comp/UserTransaction' in SerialContext [Root exception is javax.naming.NameNotFoundException: Lookup of java:comp/UserTransaction not allowed for Container managed Transaction beans]] root cause javax.naming.NamingException: Lookup failed for 'java:comp/UserTransaction' in SerialContext [Root exception is javax.naming.NameNotFoundException: Lookup of java:comp/UserTransaction not allowed for Container managed Transaction beans] root cause javax.naming.NameNotFoundException: Lookup of java:comp/UserTransaction not allowed for Container managed Transaction beans See also attached exception. After removal UserTransaction service starts working. Then I switch to the GF3.1 and RESTful ws is not available at all. Add/remove UserTransaction attribute doesn't help. It seems this is still has a relation to GF bug. But I cannot understand the exact reasons of it......
Created attachment 106547 [details] server stactrace
One more notion about GF3.1. In my case this is b40. All subsequent tries to deploy THE SAME web project which works for GF3.0.1 are failed. The project is deployed ( it is seen in the Services tab under J2EE server node ) but it doesn't work. I don't now the reasons . The server log is empty except deployment Exception (see attachment). BUT the project is deployed . The same exception appears on "Test WS" UI action. Note that it is about activation.jar. The latter jar is THE SAME AS GF3.0.1 case. There are not any exception neither on deployment nor on WS access with GF3.0.1. At the same time the exception appears each time with GF3.1 Actually I don't know why GF3.1 cares at all about activation.jar which is inside project build path not inside war file. Probably this is absolutely different issue and it could be a deployment problem.
Created attachment 106550 [details] deployment exception
ok, it seems there should be no UserTransaction and if I remove all code from xxxFacadeREST and try to insert "Use Entity Manager" it will be generated without UserTransaction. Can't say anything about this "api" usage yet.
Let's discuss here only GF3.0.1 behavior. It seems GF3.1 has a different bug ( at least b40 ) which I have described int the original issue #192733 about problem with WS itself ( not methods invocation ). In the GF3.1 case RESTful WS is not loaded at all. It is the case when WADL file is not generated on the server side.
WebJPATargetInfo.getType (it's used in generation) do not recognize this class as EJB it may be cause by class not being scanned/added to ejb model yet. It's likely the reason as it works later with insert code action.
may be the easiest fix will be to rollback issue 189559, will try to find a better solution.
will try runReadActionWhenReady for issue 189559, it may case some delays. corresponding generation shouldn't be called from awt I hope.
I don't know how WebJPATargetInfo.getType() works because this is internal impl of j2ee.persistence. But problem could be in absence of @Stateless annotation on moment of EntityManager code injection generation. So I put the EM generation code AFTER @Stateless annotation addition. This correction doesn't help actually. And one thing which I also don't understand: why UserTransaction code is generated at all? Because "utx" is not used by generated code. Client API requests only EntityManager injection and its accessor. changeset: 189603:d4768c1bf101
thanks, it still will not resolve complex cases with consequent generation with "old" model, but it can be used (if no transaction is required it doesn't matter if it's EJB or not).
Also code to get EM accessors was implemented just for facade from entity, rest from entity, it may be the only case where such generation is possible. So there is a fix: http://hg.netbeans.org/web-main/rev/cf433ccfc9b1 do not create utx member for such cases.
Integrated into 'main-golden', will be available in build *201103011142* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/d4768c1bf101 User: Denis Anisimov <ads@netbeans.org> Log: Correction for probable issue with BZ#196096 - EntityManager generator generate incorrect code