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:24:51 PST

> So.... Here are my key learnings with all of this:
> 1. You cannot use dependency injection on classes that are NOT @ManagedBeans

Which makes sense, as the container needs to have access to the Object at creation time in order to perform injection.

> 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. :(

JSF (1 OR 2) doesn't do any JPA-related injection. That is always delegated to the container. My guess is that in the myriad of jars Seam and Spring requires is the set of jar(s) required to allow Tomcat to perform that injection. I might be wrong on this, but it might be related to the JSR-250 jar. It's been a while since I've worked with a container other than GlassFish, but I vaguely recall having to include that jar if I wanted injection to work. GlassFish, being a full JavaEE stack, already has the required plumbing.

> 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");)

See the above comment/guess. :)
[Message sent by forum member 'jdlee' ]

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