persistence@glassfish.java.net

Re: NullPointerException in persist() method

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Tue, 06 Nov 2007 13:06:53 -0800

Hmmm.... Java EE 5 spec supports injection into JSF scoped managed beans (see
Table EE.5-1Component classes supporting injection).

-marina

Wouter van Reeven wrote:
> Hi,
>
> On Tue, Nov 06, 2007 at 12:47:41PM -0800, edu53 wrote:
>
>>I'm new using JPA (GlassFish V2 Server, TopLinks, NetBeans IDE) and have the
>>following problem:
>>In a managed bean that uses resource injection, i.e
>>
>>@PersistentContext
>>private EntityManager em;
>>
>>When calling em.persist(entity) always get a java.lang.NullPointerException,
>>no matter what entity trying to persist.
>>I'm not sure if resource injection is working.
>
>
> Resource injection cannot be done out of JSF managed beans, since they do not
> live inside the entity container. Getting hold of a (local or remote) session
> bean from which you use the EntityManager is one way to solve this.
>
>
> HTH, Wouter van Reeven
>