Problem with EntityManager
bard123 Apr 30, 2008 9:57 AMHi,
Here is my problem, I have a class annotated @ Stateless in this class there is a variable EntityManager annotated @ PersistenceContexte.
Here is the code:
@Stateless @Name("home") public class HomeBean implements Home{ @PersistenceContext EntityManager em; public HomeBean(){ Query q = em.createQuery("select t from TypeDocument as t"); List<TypeDocument> type = (List<TypeDocument>) q.getResultList(); } }
The problem in the constructor of the class, I use em.createQuery, and here I have is a mistake which is a null pointer exception.
Here is the error:
09:41:06,210 ERROR [STDERR] java.lang.NullPointerException 09:41:06,210 ERROR [STDERR] at sessionBeans.HomeBean.<init>(HomeBean.java:12 0) 09:41:06,210 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.new Instance0(Native Method) 09:41:06,210 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.new Instance(NativeConstructorAccessorImpl.java:39) 09:41:06,210 ERROR [STDERR] at sun.reflect.DelegatingConstructorAccessorImpl .newInstance(DelegatingConstructorAccessorImpl.java:27) 09:41:06,210 ERROR [STDERR] at java.lang.reflect.Constructor.newInstance(Con structor.java:494) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.EJBContainer.construct(EJBCont ainer.java:511) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.AbstractPool.create(AbstractPo ol.java:66) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.ThreadlocalPool.get(Threadloca lPool.java:61) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInt erceptor.invoke(StatelessInstanceInterceptor.java:54) 09:41:06,210 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo keNext(MethodInvocation.java:101) 09:41:06,210 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInte rceptor.invoke(AuthenticationInterceptor.java:77) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInt erceptor.invoke(Ejb3AuthenticationInterceptor.java:106) 09:41:06,210 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo keNext(MethodInvocation.java:101) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invo ke(ENCPropagationInterceptor.java:46) 09:41:06,210 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo keNext(MethodInvocation.java:101) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInter ceptor.invoke(AsynchronousInterceptor.java:106) 09:41:06,210 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo keNext(MethodInvocation.java:101) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.l ocalInvoke(StatelessContainer.java:214) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.l ocalInvoke(StatelessContainer.java:184) 09:41:06,210 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessLocalProxy. invoke(StatelessLocalProxy.java:81) 09:41:06,210 ERROR [STDERR] at $Proxy150.getFiltreNom(Unknown Source) 09:41:06,210 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0( Native Method)
How do I solve the problem?
Thank you