• Post Reply Bookmark Topic Watch Topic
  • New Topic

em.createQuery() .getSingleResult() cause null pointer exception!!  RSS feed

 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@PersistenceContext
private EntityManager em;

when I call
Item item = (Item)em.createQuery("select i from Item i where itcode = '1'").getSingleResult();
in class CUIDItemBean method getItem(String itcode)

the error NullPointerException is thrown!!
the full stack trace is as follow:
23:43:38,062 ERROR [[Shopping]] Servlet.service() for servlet Shopping threw exception
java.lang.NullPointerException
at hk.com.yahoo.ejb.CUIDItemBean.getItem(CUIDItemBean.java:57)
at hk.com.yahoo.web.ShoppingCart.addItem(ShoppingCart.java:42)
at hk.com.yahoo.web.Shopping.processRequest(Shopping.java:37)
at hk.com.yahoo.web.Shopping.doGet(Shopping.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)

what is wrong?
I am using NetBean 5.5.1 and JBOSS 4.2.2 GA
 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In NetBean debug mode, it say "Unknown type "em.createQuery", why??
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!