users@glassfish.java.net

EntityManager within an interceptor class?

From: Thorsten Jungblut <ulli_at_netcorner.org>
Date: Wed, 13 Jun 2007 17:14:34 +0200 (CEST)

Hi,

i got a stateless session bean:

@Stateless
@Interceptors (MyInterceptor.class)
public class MyBean {
  @Persistence (name="sample")
  EntityManager em;

  public String doSomething() {
    return (String)em.createNamedQuery("someQuery").getSingleResult();
  }
}

and an interceptor class:

public class MyInterceptor {
  @Persistence (name="sample")
  EntityManger em;

  @AroundInvoke
  public Object doSomethingElse(InvocationContext ctx) {
    return ctx.proceed();
  }
}

If i invoke the method MyBean.doSomething() remotely, it throws a
NullPointerException. Debugging through the code shows that 'em' is null.

The interceptor doesn't even do something with its 'em' instance yet.

If i remove the @Persistence... from the interceptor, everything is
working fine.

Is this a bug in GF or is there a known limitation that persistence may
not be used in interceptor classes?

Best regards
T. Jungblut