webtier@glassfish.java.net

Re: [webtier] Re: NullPointerException when using _at_ManagedBean or @PersistenceUnit in a Phase

From: <webtier_at_javadesktop.org>
Date: Wed, 02 Dec 2009 13:11:37 PST

OK! I got it to work.... kinda. (I wish it was a solution with Tomcat)

So, I was able to get it to work... I had to do 3 things:
1. Switch to GlassFish V3
2. Change my persistence.xml from using a RESOURCE_LOCAL datasource to a JTA datasource
3. Create a jdbc resource and pool with-in GlassFish

So.... Here are my key learnings with all of this:
1. You cannot use dependency injection on classes that are NOT @ManagedBeans
2. You cannot use resource injection of @PersistenceUnit if you are using Tomcat (unless somebody can prove otherwise). The unfortunate thing about this is Seam (and I believe Spring too) can do resource injection of an EntityManager in Tomcat, yet JSF 2.0 cannot. :(
3. If I want to use an EntityManager in Tomcat with JSF 2.0, I will have to do it the JSE way (Persistence.createEntityManagerFactory("MyPU");)

Thanks for your quick responses!!! JSF 2.0 still rocks! :) Please let me know if I am wrong on any of my assessments
[Message sent by forum member 'jeffcampbell' ]

http://forums.java.net/jive/thread.jspa?messageID=374380