John Fagan <John.Fagan_at_clarisource.com> wrote:
> According to the Java EE 5 Tutorial:
>
> "Unfortunately for the web application developer, resource injection
> using annotations can only be used with classes that are managed by a
> Java EE compliant container. Because the web container does not
> manage JavaBeans components, you cannot inject resources into them.
> One exception is a JavaServer Faces managed bean. These beans are
> managed by the container and therefore support resource injection.
> This is only helpful if your application is a JavaServer Faces
> application."
>
> So, according to this, if I am reading it right, JSF applications can
> use container managed beans? Maybe this is just bad documentation? I
> expected that my annotations for PersistenceContext would work based
> on this statement.
The tutorial is correct. You can inject an entity manager into a JSF
managed bean. You're trying to use a session bean as a JSF managed bean,
however. That's where your error is.
Looking at your app, there's no reason to use a session bean here. Just
recode your UserSessionBean as a regular JavaBean, and you'll be able to
use the entity manager with no problems. See bookstore6 in the tutorial
for an example.
On the other hand, if you want to use a session bean to manage the
entities to decouple it from the JSF application (for instance, if you
also had an app client), then follow what Sahoo suggested: create a
JavaBean that uses the session bean.
-i
--
Ian Evans
ian dot evans at sun dot com
Java Enterprise Edition technical documentation