users@glassfish.java.net

Re: EntityManager within an interceptor class?

From: Mahesh.Kannan <Mahesh.Kannan_at_Sun.COM>
Date: Wed, 13 Jun 2007 11:04:15 -0700

Did you try with @PersistenceContext?
@PersistenceContext (name="sample")
EntityManager em;
--Mahesh

Thorsten Jungblut wrote:

>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
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>